[Fixed]-Django Can't Find My Templates

13👍

You must use absolute paths in the TEMPLATE_DIRS setting.

Convenient thing to do, at the top of your settings, insert:

import os
DIRNAME = os.path.abspath(os.path.dirname(__file__))

Then anywhere you use a path, use os.path.join.
Example, your TEMPLATE_DIRS would become:

TEMPLATE_DIRS = (
    os.path.join(DIRNAME, 'site-templates/'),
)

40👍

I was faced to the same problem. The mistake in my case was, that the ‘app’ was not in the INSTALLED_APPS list at the project settings.py file.

The error raise an error message they suggests similar error.

line 25, in get_template TemplateDoesNotExist(template_name, chain=chain)
django.template.exceptions.TemplateDoesNotExist: authControll/index.html

settings.py –> Application definition

INSTALLED_APPS = [
    ...,
    'authControll'
]

6👍

Django has a sort of patterns and philosophy. Try to use the same configurations other wise you have to change the core patterns in django.

The pattern for templates in django are like this:

polls/templates/polls/index.html

But to use it you have to add the installed app at the configs:

INSTALLED_APPS = [
'polls.apps.PollsConfig', #<-- Here this shoud be solve it
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',]

For more information look at:

https://docs.djangoproject.com/en/3.0/intro/tutorial02/#activating-models

1👍

My mistake was simply bad positioning:

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'histories',
]

My solution was :

INSTALLED_APPS = [
'histories',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
👤Bou

0👍

This will surely solve the issue, instead of all the above try adding only below line in settings.py :

TEMPLATE_DIRS = (
    "appname/templates",
)

-6👍

http://docs.djangoproject.com/en/1.2/ref/templates/api/#loading-templates
Small fix for @zsquare answer:

import os
DIRNAME = os.path.abspath(os.path.dirname(__file__))

TEMPLATE_DIRS = ( DIRNAME+'/site-templates/' )

Leave a comment