Django应用程序工作正常,但获取TEMPLATE_*警告消息

cod*_*ing 37 python django django-1.8

当我使用runserver时,它会发出以下警告消息:

(1_8.W001)Django 1.8中不推荐使用独立的TEMPLATE_*设置,TEMPLATES字典优先.您必须将以下设置的值放入默认的TEMPLATES dict:TEMPLATE_DEBUG.

Django文档:

"TEMPLATE_DEBUG从版本1.8开始不推荐使用:在DjangoTemplates后端的OPTIONS中设置'debug'选项."

这是我的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
        },
    }, ]
Run Code Online (Sandbox Code Playgroud)

我在这里错过了什么?

Ala*_*air 79

设置debugOPTIONS你的模板设置字典.

DEBUG = True

TEMPLATES = [
    {
        ...
        'OPTIONS': {
            'debug': DEBUG,
        },
    },
]
Run Code Online (Sandbox Code Playgroud)

然后从您的设置中删除此行以停止警告

TEMPLATE_DEBUG = DEBUG
Run Code Online (Sandbox Code Playgroud)

有关如何更新模板设置的详细说明,请参阅Django文档.


OWA*_*DVL 15

删除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',
            ]
        },
    },
]
Run Code Online (Sandbox Code Playgroud)


小智 14

settings.py中删除所有这些:

    TEMPLATE_DIRS = (
        os.path.join(BASE_DIR,  'templates'),
    )
Run Code Online (Sandbox Code Playgroud)

然后在这里添加'模板':

    TEMPLATES = [
    {
        ...
        'DIRS': [here],
        ...
            ],
        },
    },
]
Run Code Online (Sandbox Code Playgroud)


小智 7

这是最好的解决方案:

将此行更改为:

TEMPLATES[0]['OPTIONS']['debug'] = True
Run Code Online (Sandbox Code Playgroud)

哪个应该修复警告.

在这里找到了它.