我的Django的結構是:Django的TemplateView在錯誤的地方尋找
testing
contacts
__init__.py
templates
contacts
index.html
(additional modules)
testing
__init__.py
templates
testing
test.html
urls.py
(additional modules)
裏面的主URL模塊,testing.urls
的,我有如下URL配置:
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',
],
},
},
]
如何在settings.py中定義模板目錄? – Mirac7
@ Mirac7更新了'settings.py'部分的問題 – inthenameofmusik