0
在django settings.py
中请求TEMPLATE_DIR
。如何在django设置中包含template_dir
而不是硬编码的路径,我想要在每个应用程序中有模板文件夹,例如,
coresite/templates
blog/templates
gallery/templates
如何才能使通用?或者是否必须为我的基本站点中的每个应用添加模板?
在django settings.py
中请求TEMPLATE_DIR
。如何在django设置中包含template_dir
而不是硬编码的路径,我想要在每个应用程序中有模板文件夹,例如,
coresite/templates
blog/templates
gallery/templates
如何才能使通用?或者是否必须为我的基本站点中的每个应用添加模板?
您可以在settings.py
文件,它会试图从每个已安装的应用程序的templates
子目录加载模板添加到django.template.loaders.app_directories.Loader
TEMPLATE_LOADERS
。
例如
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)
我试过,我曾在basesite/index.html的模板,它找不到它。然后我硬编码template_dir该路径,然后它发现 – user825904
@ user32,是_index.html_您的模板和_basesite_是您的应用程序?然后,您应该在_basesite/templates_目录中放置_index.html_并更新设置,如答案中所述。 – Rohan