TemplateDoesNotExist I got the above error when I ran the following code in Django.
views.py
from django.template.response import TemplateResponse
def product_list(request):
return TemplateResponse(request, 'catalogue/product_list.html')
What should I do. There are two places to see in setting.py.
Check if it looks like the following.
setting.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',
],
},
},
]
If this happens, it's okay. This should be the default, so it should be okay if you haven't changed it.
2.INSTALLED_APPS This was the cause of my error.
setting.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'ec.catalogue',
]
All applications in the project must be registered in INSTALLED_APPS. In other words, you also have to add the location that contains views.py and urls.py. Therefore, by adding the location where the application is stored (ec.catalogue in my case), Template can be used.
Recommended Posts