[Fixed]-TEMPLATE_DIRS is missing in settings.py (django 1.6)

18👍

Add to settings.py

from os.path import join
TEMPLATE_DIRS = (
    join(BASE_DIR,  'templates'),
)

5👍

TEMPLATE_DIRS = (
    os.path.join(BASE_DIR,  'templates'),
)

Add this to settings.py. In django 1.6 BASE_DIR is defined. Otherwise define BASE_DIR as

import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))

3👍

According to Django tutorial, you should add
TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'templates')]
to your settings.py file (so it is a list not a tuple)

2👍

It should be

TEMPLATE_DIRS = (
    os.path.join(BASE_DIR,  'templates'),
)

Or you might see an error like this :

DeprecationWarning: The TEMPLATE_DIRS setting must be a tuple. Please
fix your settings, as auto-correction is now deprecated.
self._wrapped = Settings(settings_module)

For django >= 1.6 it is a tuple

👤EliP

1👍

Use the below given code snippet. Paste it in last of the settings.py file.

from os.path import join
TEMPLATE_DIRS = (
    join(BASE_DIR,  'templates'),
)

Here BASE_DIR means your project directory, not the inner directory where the settings.py resides. Create a directory named “templates” (without quotes) inside the BASE_DIR and store your templates inside that directory. Django will join templates directory to the BASE_DIR using os.path.join() function. Hope this helps.

👤Safwan

1👍

As I posted https://stackoverflow.com/a/40145444/6333418 you have to add it to the DIR list that is inside settings.py under TEMPLATES.

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': ['[project name]/templates'], # Replace with your project name
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]
👤BFunk

Leave a comment