2012-12-04 41 views
0

在django settings.py中请求TEMPLATE_DIR如何在django设置中包含template_dir

而不是硬编码的路径,我想要在每个应用程序中有模板文件夹,例如,

coresite/templates 
blog/templates 
gallery/templates 

如何才能使通用?或者是否必须为我的基本站点中的每个应用添加模板?

回答

4

您可以在settings.py文件,它会试图从每个已安装的应用程序的templates子目录加载模板添加到django.template.loaders.app_directories.LoaderTEMPLATE_LOADERS

例如

TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader', 
    'django.template.loaders.app_directories.Loader', 
) 

更多信息:Template loader types

+0

我试过,我曾在basesite/index.html的模板,它找不到它。然后我硬编码template_dir该路径,然后它发现 – user825904

+1

@ user32,是_index.html_您的模板和_basesite_是您的应用程序?然后,您应该在_basesite/templates_目录中放置_index.html_并更新设置,如答案中所述。 – Rohan

相关问题