Django AllAuth 警告

Django AllAuth Warning

我是 Django 的新手,安装了 AllAuth 包,一切似乎都运行良好。我遵循了不同的教程,但每次执行命令 python manage.py runserver 我都会收到警告:

WARNINGS: ?: (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_CONTEXT_PROCESSORS.

这是我的一部分 settings.py:

TEMPLATES = [
{
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS': [os.path.join(BASE_DIR, 'templates')]
    ,
    'APP_DIRS': True,
    'OPTIONS': {
        'debug': DEBUG,
        'context_processors': [
            'django.template.context_processors.debug',
            'django.template.context_processors.request',
            'django.contrib.auth.context_processors.auth',
            'django.contrib.messages.context_processors.messages',
            'sekizai.context_processors.sekizai',
        ],
    },
},
]
TEMPLATE_CONTEXT_PROCESSORS = (
"django.core.context_processors.request",
"django.contrib.auth.context_processors.auth",
"allauth.account.context_processors.account",
"allauth.socialaccount.context_processors.socialaccount",
)
AUTHENTICATION_BACKENDS = (
# Needed to login by username in Django admin, regardless of `allauth`
'django.contrib.auth.backends.ModelBackend',

# `allauth` specific authentication methods, such as login by e-mail
'allauth.account.auth_backends.AuthenticationBackend',
)

感谢任何帮助。问候

自 Django 1.8+ 以来,Django 将所有 TEMPLATE_* 变量重新组合为 TEMPLATES 变量

https://docs.djangoproject.com/en/1.8/topics/templates/

这意味着您可以在 TEMPLATE var 中移动这部分代码:

"allauth.account.context_processors.account",
"allauth.socialaccount.context_processors.socialaccount",

并删除这个:

TEMPLATE_CONTEXT_PROCESSORS = (
"django.core.context_processors.request",
"django.contrib.auth.context_processors.auth",
"allauth.account.context_processors.account",
"allauth.socialaccount.context_processors.socialaccount",
)

最终结果:

TEMPLATES = [
    {
        # ...
        'OPTIONS': {
            # ...
            'context_processor': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
                'sekizai.context_processors.sekizai',
                "allauth.account.context_processors.account",
                "allauth.socialaccount.context_processors.socialaccount",
            ]
        }
    }
]

根据警告建议,您需要将 TEMPLATE_CONTEXT_PROCESSORS 设置移动到 TEMPLATES 设置中,像这样:

TEMPLATES = [
{
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS': [os.path.join(BASE_DIR, 'templates')]
    ,
    'APP_DIRS': True,
    'OPTIONS': {
        'debug': DEBUG,
        'context_processors': [
            'django.template.context_processors.debug',
            'django.template.context_processors.request',
            'django.contrib.auth.context_processors.auth',
            'django.contrib.messages.context_processors.messages',
            'sekizai.context_processors.sekizai',
            "allauth.account.context_processors.account",
            "allauth.socialaccount.context_processors.socialaccount",
        ],
    },
},
]

AUTHENTICATION_BACKENDS = (
# Needed to login by username in Django admin, regardless of `allauth`
'django.contrib.auth.backends.ModelBackend',

# `allauth` specific authentication methods, such as login by e-mail
'allauth.account.auth_backends.AuthenticationBackend',
)

所以,所有 TEMPLATE_CONTEXT_PROCESSORS 都将在 TEMPLATES 中,具有 'context_processors' 设置,谢谢。