在 django3.2 中我试图用它来定位和加载模板? 但对我不起作用
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ` [BASE_DIR / 'templates']`,
}
默认设置如下:
`from pathlib import Path`
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
有可能出现什么问题吗?
尝试使用
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
}
如果你想改变你的模板路径,你可以在你的settings.py中使用它,例如我在项目的根目录中有一个用于我的模板的“templates”目录:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
},
]
在 Django 中尝试此编辑
settings.py
TEMPLATES_DIR=BASE_DIR / 'templates'(line-17)
'DIRS':[TEMPLATES_DIR,],(line-58)
如果您的设置位置位于类似目录下
~/proj/proj/settings/local.py
那么 BASE_DIR 应该多一个
.parent
。
那么您的 DIRS 设置将不需要任何修复。