Login

Dynamically specify TEMPLATE_DIRS

Author:
ajs17
Posted:
February 28, 2007
Language:
Python
Version:
Pre .96
Tags:
configuration
Score:
-3 (after 3 ratings)

In your site’s settings.py module (in your site root), TEMPLATE_DIRS takes absolute paths. Here is a way to dynamically determine the absolute path to the application directory so you only have to specify relative paths within settings.py. Obviously, replace “application_directory” with the name of your application’s directory.

1
2
3
4
5
import os
dirname = os.path.dirname(globals()["__file__"])
TEMPLATE_DIRS = (
    os.path.join(dirname, 'application_directory/templates'),
)

More like this

  1. Dynamic Template Loader by jgeewax 7 years, 1 month ago
  2. manage.py with magic python path by bikeshedder 8 years, 2 months ago
  3. easy absolute path for settings.py by pgugged 7 years, 2 months ago
  4. Jinja2 Django integration by mathwizard 6 years, 11 months ago
  5. Ensure ugettext is available absolutely everywhere by ElfSternberg 6 years, 2 months ago

Comments

whiskybar (on February 28, 2007):

I used to use the exact same code but then I discovered you can achieve the same by

TEMPLATE_LOADERS = (
    "django.template.loaders.app_directories.load_template_source",
)
TEMPLATE_DIRS = ()

#

Please login first before commenting.