如何处理Python auth/Django Social上的AuthAlreadyAssociated?

如何处理Python auth/Django Social上的AuthAlreadyAssociated?,python,django,facebook,twitter,oauth,Python,Django,Facebook,Twitter,Oauth,我用它来连接我的网络和社交媒体 我想问一下,当使用同一个帐户注册时,如何处理错误 例如,我使用facebook注册,然后再次使用twitter注册。两者都成功注册到两个单独的帐户,当我使用我的facebook登录时,然后在我的帐户设置页面上,我想连接已注册的twitter,然后它将显示错误消息 “AuthAlreadyAssociated at/oauth/complete/twitter/” 此消息在我授权后出现在twitter重定向页面上,当它被重定向回我的网站时 简而言之,如何处理已在其

我用它来连接我的网络和社交媒体 我想问一下,当使用同一个帐户注册时,如何处理错误

例如,我使用facebook注册,然后再次使用twitter注册。两者都成功注册到两个单独的帐户,当我使用我的facebook登录时,然后在我的帐户设置页面上,我想连接已注册的twitter,然后它将显示错误消息

“AuthAlreadyAssociated at/oauth/complete/twitter/”

此消息在我授权后出现在twitter重定向页面上,当它被重定向回我的网站时

简而言之,如何处理已在其他帐户中注册的帐户

这是my views.py:

@login_required
def settings(request):
    user = request.user
    try:
        github_login = user.social_auth.get(provider='github')
    except UserSocialAuth.DoesNotExist:
        github_login = None

    try:
        twitter_login = user.social_auth.get(provider='twitter')
    except UserSocialAuth.DoesNotExist:
        twitter_login = None

    try:
        facebook_login = user.social_auth.get(provider='facebook')
    except UserSocialAuth.DoesNotExist:
        facebook_login = None

    can_disconnect = (user.social_auth.count() > 1 or 
    user.has_usable_password())

    return render(request, 'profile/settings.html', {
        'github_login': github_login,
        'twitter_login': twitter_login,
        'facebook_login': facebook_login,
        'can_disconnect': can_disconnect
    })
这是我的settings.html模板:

{%extends“base.html”%}
{%load crispy_forms_tags%}
{%block title%}Navhi微博-个人资料{%endblock%}
{%block content%}

{%include'profile/base_profile.html%} {%if github_login%} {%if能断开%} {%csrf_令牌%} 断开与GitHub的连接 {%else%}

在断开与Github的连接之前,您必须为您的帐户注册密码。您的问题已在此处得到回答:

基本上,答案是覆盖
social\u auth.middleware.SocialAuthExceptionMiddleware
类中的默认方法
process\u exception()
,并将此中间件添加到settings.py中

有关如何在此处覆盖的详细信息:

可能重复的