setting.py 用户认证配置
# 指定自定义用户认证
AUTHENTICATION_BACKENDS = (
'user.backend.LoginMobileUsernameModelBackend',
# django admin所使用的用户登录与django-allauth无关
'django.contrib.auth.backends.ModelBackend',
# `allauth` specific authentication methods, such as login by e-mail
'allauth.account.auth_backends.AuthenticationBackend',
)
# 第三方微信
SOCIALACCOUNT_PROVIDERS = {
'weixin': {
'AUTHORIZE_URL': 'https://open.weixin.qq.com/connect/oauth2/authorize', # for media platform
'SCOPE': ['snsapi_base'],
}
}
在登录视图中使用了login()
# 将用户数据保存在 session 中,即实现了登录动作
login(request, user)
会报出错误
You have multiple authentication backends configured and therefore must provide the `backend` argument or set the `backend` attribute on the user.
解决方案:
login(request, user, backend='django.contrib.auth.backends.ModelBackend')