Space guy
Space guy

Reputation: 415

Django redirect to previous/current URL after LOGOUT

Although the question is simple I can't figure a way out to make this work.

I have many pages on a website and each page displays a button for the user to LOGOUT. If the user clicks on the button in some specific page the logout redirect should send them to the same page.

Since I'm using the LOGOUT_REDIRECT_URL = '/' in my setting.py the Logout buttons always redirects me to my home page.

Thanks in advance.

Upvotes: 0

Views: 471

Answers (1)

Vitor Diniz
Vitor Diniz

Reputation: 363

You can send a next_url attribute to the logout request which Django LogoutView uses to know to which page redirect after the logout. Something like:

<a href="{% url 'auth_logout' %}?next={{request.path}}"> Logout</a>

Upvotes: 3

Related Questions