Reputation:
Can't understand why Django can't find the template.
project/templates/blog/intro.html
:
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
{% ifis_admin %}
<p>{{username}} is an admin!</p>
{% endif %}
<h1>My First Heading</h1>
<p>My first paragraph.</p>
</body>
</html>
views.py
:
from django.shortcuts import render
from django.shortcuts import render_to_response
# Create your views here.
def intro(request):
render(request, "blog/intro.html")
Error: TemplateDoesNotExist at blog/intro.html
EDIT: Also templates settings. Not sure, but it seems to be all right
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',
],
},
},
]
Upvotes: 2
Views: 460
Reputation: 3630
You need to set DIRS
in your TEMPLATES
settings. If the folder is set like you mention at the top. This adds the templates directory as long as it is at the root of the project. Same level as the manage.py
.
'DIRS': [os.path.join(BASE_DIR, 'templates')],
Upvotes: 1
Reputation: 11
If blog is your app and project is your djangoproject : By the docs(https://docs.djangoproject.com/en/1.10/intro/tutorial03/) you need to put your template in project/blog/templates/blog/intro.html Sry about my english
Upvotes: 1