不明白为什么Django找不到模板。
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")
错误:TemplateDoesNotExist at blog/intro.html
编辑:还有模板设置。不确定,但好像还可以
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',
],
},
},
]
请您参考如下方法:
如果 blog 是你的应用,而 project 是你的 djangoproject: 根据文档(https://docs.djangoproject.com/en/1.10/intro/tutorial03/),您需要将模板放入 项目/博客/模板/博客/intro.html 对不起我的英语
