社交注册后Django allauth重定向 [英] Django allauth Redirect after social signup

查看:100
本文介绍了社交注册后Django allauth重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

社交注册后,我想重定向到某个链接,该怎么做?在哪里进行?我可以进行常规注册,但不能进行社交注册.

I would like to redirect to a certain link after social signup, how and where do I do that? I can do it for regular signup but I can't for social signup.

推荐答案

或者,您也可以编写自己的自定义

Alternatively you can write your own custom social account adapter to handle different logged in redirection from different social accounts and not messing with your normal account settings, like so:

# adapter.py    
from allauth.socialaccount.adapter import DefaultSocialAccountAdapter

class SocialAccountAdapter(DefaultSocialAccountAdapter):
    def get_login_redirect_url(self, request):
        # do your logic here for different social accounts
        ...
        return 'url/to/your/redirection' # or reverse(view) or whatever

# settings.py
SOCIALACCOUNT_ADAPTER = "point.to.adaptor.SocialAccountAdapter"

如果要更改新注册的重定向,则可以自定义适配器的 save_user 方法:

class SocialAccountAdapter(DefaultSocialAccountAdapter):
    ...
    def save_user(self, request, sociallogin, form=None):
        super(DefaultSocialAccountAdapter, self).save_user(request, sociallogin, form=form)
        # your logic here... and return redirection afterward
        return redirect(...)

这篇关于社交注册后Django allauth重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆