1

在 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 

任何线索可能是什么问题?

4

2 回答 2

0

如果你想改变你的模板路径,你可以在你的 settings.py 中使用它,例如我在项目的根目录中为我的模板有一个“模板”目录:

    TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')],
        'APP_DIRS': True,
    },
]
于 2021-04-28T09:19:17.693 回答
0

尝试使用

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')],
    }
于 2021-04-28T06:04:58.730 回答