我通过设置:
在settings.py文件中包含了我的模板文件夹的路径TEMPLATE_DIR = os.path.join(BASE_DIR, 'templates')
同样适用于STATIC_FILES_DIR
,但我一直收到TemplateDoesNotExist
错误。当我看到错误的死后,我看到了:
Django tried loading these templates, in this order:
Using loader django.template.loaders.filesystem.Loader:
Using loader django.template.loaders.app_directories.Loader:
C:\Python27\lib\site-packages\django\contrib\admin\templates\home.html (File does not exist)
C:\Python27\lib\site-packages\django\contrib\auth\templates\home.html (File does not exist)
为什么template.loader会在该目录中查找模板文件而不是我settings.py
文件中指定的模板文件?此外,当我将home.html
页面复制到错误消息中提到的第一个目录时,页面加载内容时没有错误,因此如何让加载程序从其搜索的位置移动到目录所在的位置文件实际上位于?
答案 0 :(得分:2)
有效设置名称是TEMPLATE_DIRS
,它是字符串的元组,而不是简单的字符串:
TEMPLATE_DIRS = (os.path.join(BASE_DIR, 'templates'), )