Django allauth Redirect after social signup

て烟熏妆下的殇ゞ 提交于 2019-12-10 15:05:29

问题


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.


回答1:


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"

Edited:

In case you want to alter the redirection for newly signed up, you may customise adapter's save_user method:

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(...)



回答2:


After both social and normal it should be redirecting to your LOGIN_REDIRECT_URL in settings. Do you have that set?

Theres also some good information here about custom redirection



来源:https://stackoverflow.com/questions/27759407/django-allauth-redirect-after-social-signup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!