关于 Django 3.2 App下 TemplateDoesNotExist报错的问题.
- [当前的目录结构. ]
- [settings 的配置 ]
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [BASE_DIR / 'templates', ],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
- [ 报错]
这是正常的写法,但是会造成别的app下的文件无法正常被读取.
-
[ 修改.]
-
[成功访问 ]
总结:
'DIRS': [BASE_DIR / 'templates', 'run_result/temlpates'],
BASE_DIR / 'templates' 外层的总目录.
'run_result/temlpates' 自己添加的app下的templates.