python-social-auth custom redirect url in Django

走远了吗. 提交于 2019-12-10 16:54:19

问题


I am using python-social-auth package along with Django to manage oauth and openID logins.

Now the issue is that, I can specify one redirect url in django settings.py, but in some case I want the user to be redirected to the same page from which he initiated the authentication process.

E.g: if my redirect url is : /home/ and I am currently in a page /products/product1 from which I authenticate the user, then I want the user to be redirected to /products/product1/ rather than /home/

Please help me solve this problem or at least some materials that covers this in detail.

Thanks in advance


回答1:


I'm pulling your answer out of the question and placing it here for future reference.

Adding a parameter ?next={{request.get_full_path}} to the auth url.




回答2:


A bit better is to conditianally add next when it exsists

 <a href="{% url 'social:begin' "google-oauth2" %}
    {% if request.GET.next %}?next={{request.GET.next}}{% endif %}">
      <img src="{{ STATIC_URL }}images/login-google.png" alt="Google">
 </a>


来源:https://stackoverflow.com/questions/19906526/python-social-auth-custom-redirect-url-in-django

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