Reputation: 11
I'm starting a very simple Django app but having trouble with extending an html file.
I have base.html
and index.html
both within my_site/my_app/templates/my_app
.
i.e.
my_site/my_app/templates/my_app/base.html
and my_site/my_app/templates/my_app/index.html
.
Within the index.html
file I have {% extends 'base.html' %}
.
My settings.py
file has
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
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',
],
},
},
]
But when I visit my index view at http://127.0.0.1:8000/index/
:
def index(request):
return render(request, 'my_app/index.html')
I get the following error:
TemplateDoesNotExist at /index/
base.html
Request Method: GET
Request URL: http://127.0.0.1:8000/index/
Django Version: 1.10.3
Exception Type: TemplateDoesNotExist
Exception Value: base.html
Do I have the base.html
file saved in the wrong place or is it something else? I have not been able to solve this.
Upvotes: 1
Views: 2162
Reputation: 599610
It should be in my_site/my_app/templates or my_site/templates.
Upvotes: 2