Python Django 应用程序运行良好,但收到 TEMPLATE_* 警告消息
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32445953/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Django app works fine, but getting a TEMPLATE_* warning message
提问by codingcoding
When I use runserver, it gives this warning message:
当我使用 runserver 时,它会给出以下警告消息:
(1_8.W001) The standalone TEMPLATE_* settings were deprecated in Django 1.8 and the TEMPLATES dictionary takes precedence. You must put the values of the following settings into your default TEMPLATES dict: TEMPLATE_DEBUG.
(1_8.W001) Django 1.8 中不推荐使用独立的 TEMPLATE_* 设置,并且 TEMPLATES 字典优先。您必须将以下设置的值放入默认的 TEMPLATES dict 中:TEMPLATE_DEBUG。
Quoth the Django Documentation:
引用 Django 文档:
"TEMPLATE_DEBUG Deprecated since version 1.8: Set the 'debug' option in the OPTIONS of a DjangoTemplates backend instead."
“TEMPLATE_DEBUG 自 1.8 版起已弃用:改为在 DjangoTemplates 后端的 OPTIONS 中设置 'debug' 选项。”
Here is my settings.py with my futile attempts to fix it:
这是我的 settings.py 尝试修复它是徒劳的:
DEBUG = True
TEMPLATE_DEBUG = DEBUG
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'myapp/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',
],
'debug': DEBUG,
'DEBUG': DEBUG,
'TEMPLATE_DEBUG': DEBUG
},
}, ]
What am I missing here?
我在这里缺少什么?
采纳答案by Alasdair
Set debug
in OPTIONS
dictionary of your templates settings.
设置debug
在OPTIONS
你的模板设置字典。
DEBUG = True
TEMPLATES = [
{
...
'OPTIONS': {
'debug': DEBUG,
},
},
]
Then remove this line from your settings to stop the warnings
然后从您的设置中删除此行以停止警告
TEMPLATE_DEBUG = DEBUG
See the Django docsfor detailed instructions how to update your template settings.
有关如何更新模板设置的详细说明,请参阅Django 文档。
回答by Joni
In my setting.py
in django
, there is not this script :
在我的setting.py
in 中django
,没有这个脚本:
TEMPLATE_DEBUG = DEBUG
TEMPLATE_DEBUG = DEBUG
and
和
'debug': DEBUG,
'DEBUG': DEBUG,
'TEMPLATE_DEBUG': DEBUG
'debug': DEBUG,
'DEBUG': DEBUG,
'TEMPLATE_DEBUG': DEBUG
Maybe you can try to remove them and run it again.
也许您可以尝试删除它们并再次运行它。
回答by Maxim Agapov
回答by dev.ICE
From settings.pyremove all this:
从settings.py 中删除所有这些:
TEMPLATE_DIRS = (
os.path.join(BASE_DIR, 'templates'),
)
Then add 'templates'here:
然后在此处添加“模板”:
TEMPLATES = [
{
...
'DIRS': [here],
...
],
},
},
]
回答by OWADVL
remove APP_DIRS and add the loaders inside the templates. example:
删除 APP_DIRS 并在模板中添加加载器。例子:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')]
,
'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',
],
'loaders': [
'django_jinja.loaders.AppLoader',
'django_jinja.loaders.FileSystemLoader',
]
},
},
]