Getting TemplateDoesNotExist error in django 1.9

Today I ran into a very strange problem. I get a TemplateDoesNotExist (see. The first image), but when I tried to debug the template source using the debug-toolbar , it correctly shows the path to the templates (see image 2) More strange, when I clicked the specific templates button, it will show the template source correctly .

This is the first time I have encountered such problems. Can someone explain why I am getting this error.

EDIT: adding settings.py file (link)

SETTINGS_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [os.path.join(SETTINGS_PATH, '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', ], }, }, 

]

thanks

enter image description here

enter image description here )

+5
source share
2 answers

I had a similar problem with Django 1.9. I just changed the DIRS in the TEMPLATES of the settings.py file.

try it

 'DIRS': [os.path.join(BASE_DIR,'templates')], 

Instead

 'DIRS':[os.path.join(SETTINGS_PATH,'templates')], 

Try this code instead of your TEMPLATES

 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', ], }, },] 
+14
source

Today I rose to 1.9 and suddenly ran into the same problem. It seems to me that adding "APP_DIRS": "True", a trick is used for templates (I changed it several times by adding / removing this, and it works / doesn't work).

So what APP_DIRS does: if I understand the documentation ( https://docs.djangoproject.com/en/1.9/ref/templates/api/ ), it correctly reads the default Django templates if True. In principle, for 95% of all projects this should be so.

+4
source

Source: https://habr.com/ru/post/1241750/


All Articles