Python 如何在django设置中包含模板_dir
在djangoPython 如何在django设置中包含模板_dir,python,django,Python,Django,在djangosettings.py中,它请求TEMPLATE\u DIR 与其在那里硬编码路径,我希望在每个应用程序中都有templates文件夹,例如 coresite/templates blog/templates gallery/templates 怎样才能使它通用?或者我必须为我的基本站点中的每个应用程序添加模板吗?您可以将django.template.loaders.app\u目录.Loader添加到settings.py文件中的template\u loaders中,该文件将
settings.py
中,它请求TEMPLATE\u DIR
与其在那里硬编码路径,我希望在每个应用程序中都有templates文件夹,例如
coresite/templates
blog/templates
gallery/templates
怎样才能使它通用?或者我必须为我的基本站点中的每个应用程序添加模板吗?您可以将
django.template.loaders.app\u目录.Loader
添加到settings.py
文件中的template\u loaders
中,该文件将尝试从每个已安装的应用程序的templates
子目录加载模板
e、 g
更多信息:您可以将
django.template.loaders.app_目录.Loader
添加到settings.py
文件中的template_loaders
中,该文件将尝试从每个已安装应用的templates
子目录加载模板
e、 g
更多信息:我试过了,我把模板放在basesite/index.html中,但它找不到。然后我在template_dir中硬编码了该路径,然后找到了它that@user32,index.html是您的模板吗?basesite是您的应用程序吗?然后你应该把index.html放在basesite/templates目录中,并按照回答中所说的更新设置。我试过了,我把模板放在basesite/index.html中,但它找不到。然后我在template_dir中硬编码了该路径,然后找到了它that@user32,index.html是您的模板吗?basesite是您的应用程序吗?然后,您应该将index.html放在basesite/templates目录中,并按照答案中所述更新设置。
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)