TEMPLATE_DIRS relative to the project folder

Posted: January 21st, 2010 | Author: | Filed under: Django | Tags: , | 1 Comment »

When developing with Django we need to specify our templates directory inside the settings.py with the TEMPLATE_DIRS directive. When it comes to deploying or publising the application we often forget to change this setting to the new folder where the application will be deployed. In order to counter this, it is possible to make this setting dynamic with the following in setting.py

import os.path
PROJECT_DIR = os.path.dirname(__file__) # this is not Django setting.
    os.path.join(PROJECT_DIR, "templates"),
    # here you can add another templates directory if you wish.

One Comment on “TEMPLATE_DIRS relative to the project folder”

  1. 1 Shaun said at 4:39 pm on March 23rd, 2010:

    Thank you very much.