Redirect to last page not working on python social auth

I am using python social auth to use social logins, but I cannot redirect to the last page after a successful login.

For example, if I go to the next page http://localhost:8000/docprofile/14/ and click the login button, instead of redirecting me to the last page http://localhost:8000/docprofile/14/ , it redirects me to the login page.

If I put this:

 <a href="{% url 'social:begin' 'facebook' %}?next={{ request.path }}"> | Login with Facebook</a> 

It redirects the login page and the URL ends with strange characters:

 http://localhost:8000/login/#_=_ 

I also tried this:

 <a href="{% url 'social:begin' 'facebook' %}?next={{ request.get_full_path }}"> | Login with Facebook</a> 

This time, it follows the path /docprofile/14 , but still does not redirect me back to the login page with the URL http://localhost:8000/login/?next=/docprofile/14/#_=_

+5
source share
2 answers

You can include this at the top of the redirected page template -

 <script type="text/javascript"> if (window.location.hash == '#_=_') { window.location.hash = ''; } </script>` 

It will be a trick!

0
source

I needed to disable the next parameter from the query string in my GET and modify the html to include it in a template like this

 def home(request): c = context() if request.GET.get('next'): c = context(next=request.GET['next']) return render_to_response('home.html', context_instance=RequestContext(request, c)) def context(**extra): return dict({ 'available_backends': load_backends(settings.AUTHENTICATION_BACKENDS) }, **extra) 

And my template now gets the next parameter from the context and when I register the redirect.

 <a class="col-md-2 btn btn-default" name="{{ backend|backend_class }}" href="{% url "social:begin" backend=name %}?next={{next}}"> 
0
source

Source: https://habr.com/ru/post/1206956/


All Articles