0
点赞
收藏
分享

微信扫一扫

配置了多个身份验证后端,因此必须提供`backend`参数或在用户上设置`backend`属性


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')

 

举报

相关推荐

0 条评论