当 AppDirs 在 Django 中设置为 True 时,我可以在哪里放置模板加载器 - Django-admin-tools
Where can I put template loaders when AppDirs is set to True in Django - Django-admin-tools
我正在尝试使用一个名为 django-admin-tools
的模块。它要求我将 'admin_tools.template_loaders.Loader'
放在模板的顶部。我有 AppDirs: True
这意味着我不能在模板的选项部分使用 'loaders'
选项。当 AppDirs
设置为 True
时,我可以将 'admin_tools.template_loaders.Loader'
放在哪里?
根据 this doc,当 APP_DIRS
为 True 时,这意味着 django 只使用 django.template.loaders.app_directories.Loader
.
所以我认为您不必将 APP_DIRS
设置为 True。只需在 loaders
中附加 admin_tools.template_loaders.Loader
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': False,
'OPTIONS': {
...,
'loaders': [
'django.template.loaders.app_directories.Loader',
'admin_tools.template_loaders.Loader',
...
],
},
},
]
我正在尝试使用一个名为 django-admin-tools
的模块。它要求我将 'admin_tools.template_loaders.Loader'
放在模板的顶部。我有 AppDirs: True
这意味着我不能在模板的选项部分使用 'loaders'
选项。当 AppDirs
设置为 True
时,我可以将 'admin_tools.template_loaders.Loader'
放在哪里?
根据 this doc,当 APP_DIRS
为 True 时,这意味着 django 只使用 django.template.loaders.app_directories.Loader
.
所以我认为您不必将 APP_DIRS
设置为 True。只需在 loaders
中附加 admin_tools.template_loaders.Loader
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': False,
'OPTIONS': {
...,
'loaders': [
'django.template.loaders.app_directories.Loader',
'admin_tools.template_loaders.Loader',
...
],
},
},
]