Fixing TemplateDoesNotExist Django error

Django is a popular Python web framework. Because it is popular, a lot of people are learning Django. And if you’ve just started learning Django and are stuck with TemplateDoesNotExist error, see the solution in this article.

“TemplateDoesNotExist at /” error

So, when developing your Python Django web application, you can encounter the following error:

TemplateDoesNotExist at /

Request Method: GET
Request URL: http://localhost:8000/
Django Version: 3.2
Exception Type: TemplateDoesNotExist
Python Executable: /usr/bin/python3
Python Version: 3.9.8

Django tried loading these templates in, this order:
Using engine django:
django.template.loaders.filesystem.Loader: ...

The error has long traceback next to it. This error means that Django framework cannot find a template for requested URL. If you already have your templates/ and trying to render them, go ahead to Fix #3. There are few possible reasons Django can issue that error. Let’s consider them below.

Fix #1: add templates

Make sure you add actual templates to your templates folder. If you don’t have any templates, create templates in the base directory of your website and add a template (for example, index.html). I will assume your app is named “app” and the project name is “website”. The structure of your project will look like this:

├── app
│   ├──
│   ├──
│   ├──
│   ├── migrations
│   ├──
│   ├──
│   ├──
│   └──
├── templates
│   └── app
│       └── index.html
└── website

Fix #2: check settings, route URLs, write views

  1. Go to website/ and check if your app is present in INSTALLED_APPS list. If not, add it and run python3 makemigrations; python3 migrate.
  2. Go to website/ and make sure it has path('', include('app.urls')), line in the urlpatterns array.
  3. Check if app/ has line from . import views at the top and path('', views.index, name='index'), in the urlpatterns array.
  4. Go to app/ and ensure it has index function which serves the index page. If not, write this to your app/
from django.shortcuts import render

def index(req):
    return render(req, 'app/index.html')

Next, restart your web server and check if error is gone. If not, try Fix #3.

Fix #3: specify templates directory in settings

Go to your main website/ file and find the TEMPLATES array.

Add 'DIRS': [ BASE_DIR / 'templates' ], line to make the array look like this:

        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [ BASE_DIR / 'templates' ],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [

If you are wondering, “/” (slash) operator from pathlib module concatenates two Path objects properly. After the third fix, your app should finally work.


To recap, when you encounter TemplateDoesNotExist in Django application, you should do the following things to fix it:

  • Create templates directory with app name directory in it, which contains HTML files.
  • Check settings of your application, edit them if needed.
  • Route URLs, write page function in file.
  • Add BASE_DIR/'templates' in the TEMPLATES array.
  • Restart your app.

Leave a Comment