django.template.exceptions.TemplateDoesNotExist


Django by default will look for the ‘templates’ folder under each app. For example below template folders will be located by default:

project
   - app1_name
      -templates
        -app1_name
 
   - app2_name
      -templates
        -app2_name

However, Django will throw an django.template.exceptions.TemplateDoesNotExist when you use a different layout from above, such as when you have a single ‘templates’ folder located under your project instead of under individual apps:

project
  - app1_name
  - app2_name
templates

In order for this to work, you will need to tell Django to locate the templates folder in the base directory.

The fix is to edit your Django settings file, locate the ‘TEMPLATES’ tuple, and add [os.path.join(BASE_DIR, ‘templates’)]
as shown below:

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')],
        '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',
            ],
        },
    },
]
Rate this article
Sending
User Review
0 (0 votes)


About Matthias 33 Articles
I am a Software Engineer from Houston, TX who love to write codes that brings great ideas to live. In my professional life, I have created software for different industries including Oil & Gas, Finance, Service Provider, Cloud Computing and Embedded Systems. When not writting codes, i enjoy travelling, good music and photography. You can reach me at me@matthiasomisore.com.

Be the first to comment

Leave a Reply

Your email address will not be published.


*