以下是我的文件夹结构
geoff
settings.py
urls.py //using this
wsgi.py
homepage
migrations->folder
_init_.py
.....others here
views.py
index.html
在我的geoff urls // root url
中from homepage import views as homepage
urlpatterns = [
url(r'^$', homepage.home, name = 'homepage')
]
主页上没有views.py
def home(request):
template = loader.get_template('index.html')
context = RequestContext(request, {
'latest_poll_list': "new",
})
return HttpResponse(template.render(context))
以上引发错误
TemplateDoesNotExist at
homepage.html
可能出现什么问题?
更新SETTINGS.PY
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'homepage.apps.HomepageConfig'
)
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',
],
},
},
从上面的ive已经在设置中包含了主页应用程序,但仍无法正常工作。
答案 0 :(得分:2)
您的模板设置应如下所示:
TEMPLATES = [
{
####
'DIRS': [os.path.join(BASE_DIR, 'templates')]
####
}
]
然后你的文件夹结构:
templates
index.html
...other html
geoff
settings.py
urls.py //using this
wsgi.py
homepage
migrations->folder
_init_.py
.....others here
views.py