Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在django设置中包含模板_dir_Python_Django - Fatal编程技术网

Python 如何在django设置中包含模板_dir

Python 如何在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中,该文件将

在django
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',
)