我有以下树形结构:
project/
__init__.py
app/
__init__.py
templates/
home.html
base.html
settings.py
urls.py
views.py
wsgi.py
views.py
from django.shortcuts import render_to_response
from django.template.context import RequestContext
from django.template.loader import get_template
def home(request):
context = RequestContext(request,
{'user': request.user})
return render_to_response('templates/home.html',
context_instance=context)
urls.py
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^$', 'app.views.home', name='home'),
]
settings.py的相关部分
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'app'
]
...
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',
],
},
},
]
问题:当我跑步时:
django.template.exceptions.TemplateDoesNotExist: templates/home.html
我尝试了不同的路径变体以及将目录硬编码到我的设置文件中的TEMPLATES字典中。我错过了什么?
答案 0 :(得分:0)
此设置很好。问题是我在home.html中扩展了base.html
赞:{% extends 'app/base.html' %}
需要{% extends 'base.html' %}