【发布时间】:2021-07-15 18:00:17
【问题描述】:
现在在我的项目的 Django 设置文件中,我正在尝试构建一个路径,以便我可以显示我的模板/项目/index.html 文件。我可以寻求帮助解决这个问题吗?
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
在我的 TEMPLATES 字典中,这是 DIRS
`TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
os.path.join(BASE_DIR, 'projects/templates'),
],`
【问题讨论】:
-
我注意到您在问题中说
templates/projects,但在代码中说projects/templates——除此之外,还有什么没有按预期工作?有任何错误或意外行为吗? -
projects/templates/projects/index.html 是我目前的设置方式。我收到 NameError 的名称错误:未定义名称“os”。
-
这可以通过在文件顶部的某处添加
import os来解决。您需要对您的问题提供更详细的解释才能成为适合 SO 的问题,请参阅How do I ask a good question?。
标签: python django django-templates