Django无法找到加载模板/ css的位置

时间:2015-04-04 22:55:08

标签: python django templates django-templates django-settings

我通过设置:

在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页面复制到错误消息中提到的第一个目录时,页面加载内容时没有错误,因此如何让加载程序从其搜索的位置移动到目录所在的位置文件实际上位于?

1 个答案:

答案 0 :(得分:2)

有效设置名称是TEMPLATE_DIRS,它是字符串的元组,而不是简单的字符串:

TEMPLATE_DIRS = (os.path.join(BASE_DIR, 'templates'), )