In my template I am currently using the next
parameter to redirect the user back to the page before the login page with this:
<a href="{% url auth_login %}?next={% firstof request.path '/' %}">Log in</a>
The firstof
tag makes sure that in case request.path
is invalid, then it will redirect back to the root URL.
This works well on every page except one: the logout page. If I wanted to switch user, then I would first log out, then click log in. But then my url would be
http://127.0.0.1:8000/accounts/login/?next=/accounts/logout/
So as soon as I log in, I would immediately be logged back out again. How do I modify the template so with something like this pseudocode:
if request.path and request.path != reverse( 'auth_logout' )
return request.path
return "/"