TemplateDoesNotExist at/

I wasted a lot of time trying to figure out what was wrong with my 'templates' directory and figured out :

You may have forgotten to add TEMPLATE_DIR in the following segment of settings.py :

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        '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',
            ],
        },
    },
]

So it should have 'DIRS': [TEMPLATE_DIR,], instead of 'DIRS': [],


The reason might be that django is trying to look for your templates directory in the directory with your setting.py file Whereas actually the templates directory is in the parent directory. Try doing something like this in your settings.py

SETTINGS_PATH = os.path.dirname(__file__)
PROJECT PATH = os.path.join(SETTINGS_PATH, os.pardir)
PROJECT_PATH = os.path.abspath(PROJECT_PATH)
TEMPLATES_PATH = os.path.join(PROJECT_PATH, "templates")

TEMPLATE_DIRS = (
    TEMPLATES_PATH,
)

The error usually is due to incorrectly configured templates directory


From what you've shown, I think you may have a problem with your project layout.

Usually, it is set as follows :

├── manage.py
├── yourproject
│   ├── __init__.py
│   ├── settings.py
│   ├── templates
│   ├── urls.py
│   ├── wsgi.py
│   └── wsgi.pyc
├── yourfirstapp
│   ├── __init__.py
│   ├── admin.py
│   ├── models.py
│   ├── templates
│   ├── tests.py
│   ├── urls.py
│   └── views.py
├── yoursecondapp
    ├── __init__.py
    ├── admin.py
    ├── models.py
    ├── templates
    ├── tests.py
    ├── urls.py
    └── views.py

As you can see, each app inside your project can have it's own templates directory.yourproject is a bit particuliar, because it also stores unique files, such as settings.pyand wsgi.py. However, you can consider and use it as an app.

Now, if you want to use a template stored in yourproject/templates, you'll have to add yourproject to your INSTALLED_APPS settings.

Does it helps ? If not, can you edit your original post with your project layout ?


I know this is late, but the solutions mentioned here did not work for me. So here is what works:

  1. inside the settings.py file, add your appConfig in installed apps.
INSTALLED_APPS = [ '...', 'AppName.apps.AppNameConfig', ]
  1. create a templates directory appName/templates/appName. (where appName is the name of your app).

  2. When you call your render function, then you can pass it templates.name.html. Like so:

return render(request, 'templates/blog.html')