我的 Django 结构是:
testing
contacts
__init__.py
templates
contacts
index.html
(additional modules)
testing
__init__.py
templates
testing
test.html
urls.py
(additional modules)
在主 URL 模块内部testing.urls
,我有一个 urlconf,如下所示:
url(r'^testing/$', TemplateView.as_view(template_name='testing/test.html'))
问题是,它一直在寻找contacts.templates.contacts
文件test.html
。使用现有的 urlcon,调试页面显示以下内容:
模板加载器事后分析
Django tried loading these templates, in this order:
Using loader django.template.loaders.filesystem.Loader:
Using loader django.template.loaders.app_directories.Loader:
/Library/Python/2.7/site-packages/django/contrib/admin/templates/testing/test.html (File does not exist)
/Library/Python/2.7/site-packages/django/contrib/auth/templates/testing/test.html (File does not exist)
/Users/*/Developer/django/testing/contacts/templates/testing/test.html (File does not exist)
contacts
出于某种原因,它始终默认为.......................^^^^^^^^^^文件夹。TemplateView 是否有其他参数或template_name
可以控制它?任何帮助表示赞赏!
更新 - 内部settings.py
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',
],
},
},
]