为什么 settings.py 中的这段代码没有覆盖默认的 Django 项目模板?
Why didn't this code in settings.py override the default Django project template?
我正在学习非常基础的教程 here,我正在使用我自己的 base_site.html 模板而不是默认模板,后者具有不同的 header 文本。
我将默认模板复制到我的模板文件夹中,修改它,然后在 settings.py 中链接新模板:
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(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',
],
},
},
]
没有骰子。
当我采用更简单的路线并将其与下面的单行链接时,它很容易工作:
TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'templates/')]
太棒了!但是现在我想知道为什么原来的代码不起作用。
如果有帮助,我的文件夹结构是:
- Scripts
- mysite
- mysite
- polls
- templates
- admin
base_site.html
TEMPLATES
设置将在django 1.8中引入。它在当前的 django 1.7 中不可用。
因此请阅读 the tutorial 以了解您使用的实际 django 版本。
我正在学习非常基础的教程 here,我正在使用我自己的 base_site.html 模板而不是默认模板,后者具有不同的 header 文本。
我将默认模板复制到我的模板文件夹中,修改它,然后在 settings.py 中链接新模板:
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(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',
],
},
},
]
没有骰子。
当我采用更简单的路线并将其与下面的单行链接时,它很容易工作:
TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'templates/')]
太棒了!但是现在我想知道为什么原来的代码不起作用。
如果有帮助,我的文件夹结构是:
- Scripts
- mysite
- mysite
- polls
- templates
- admin
base_site.html
TEMPLATES
设置将在django 1.8中引入。它在当前的 django 1.7 中不可用。
因此请阅读 the tutorial 以了解您使用的实际 django 版本。