2015-04-04 61 views
0

/CSS我包括路径在settings.py文件我的模板文件夹设置:Django中找不到位置加载模板从

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页面复制到错误消息中提到的第一个目录中时,该页面无错误地加载内容,那么如何让加载程序从搜索的位置移动到文件所在的目录位于?

回答

2

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

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

注为未来的用户:此设置有利于['TEMPLATES'(HTTPS的弃用:// docs.djangoproject.com/en/1.8/ref/templates/upgrading/#the-templates-settings)从Django 1.8开始。 – Selcuk 2015-04-04 23:07:10

+0

是否有另一种可能的解释?即使进行此更改,错误仍然存​​在。 – 2015-04-04 23:17:30

+0

@Selcuk是的,你说得对。但设置stilll复数'DIRS'和元组类型:-) – catavaran 2015-04-05 02:03:47