Django allauth 重定向到注册

dar*_*der 2 python django django-allauth

我正在使用 django all-auth 包来允许人们通过 g+ oauth2 登录。问题在于,在服务器上,登录会导致其重定向到 /accounts/social/signup 页面,而不是直接登录并返回主页。

这是所需的代码详细信息

设置.py

LOGIN_URL = '/accounts/google/login/'
LOGIN_REDIRECT_URL = '/'
SOCIALACCOUNT_QUERY_EMAIL = True
ACCOUNT_UNIQUE_EMAIL = True
ACCOUNT_EMAIL_REQUIRED = True
SOCIALACCOUNT_PROVIDERS = {
    'google': {
    'SCOPE': [
    'https://www.googleapis.com/auth/userinfo.email',
     'https://www.googleapis.com/auth/userinfo.profile',
     'https://www.googleapis.com/auth/plus.login',
     'https://www.googleapis.com/auth/plus.me'
     ],
     'AUTH_PARAMS': {'access_type': 'online'}
    }
}
SOCIALACCOUNT_ADAPTER = 'lostndfound.views.LoginAdapter'
Run Code Online (Sandbox Code Playgroud)

LostndFound.views

class LoginAdapter(DefaultSocialAccountAdapter):
    def pre_social_login(self, request, sociallogin):
        user = sociallogin.account.user
        if user.email.split('@')[-1] not in settings.ALLOWED_LOGIN_HOSTS:
            messages.error(request, "You can login only through an *** account.")
            raise ImmediateHttpResponse(HttpResponseRedirect(reverse('home')))
Run Code Online (Sandbox Code Playgroud)

dar*_*der 5

我使用了我尝试登录的电子邮件 ID 作为管理站点超级用户的电子邮件 ID。由于电子邮件不是唯一的,这导致了冲突。我只是更改了超级用户的电子邮件。