Django logout infinite loop?
django
Solution
You have written:
def logout(request):
logout(request)
which means You call the view itself - not the `logout` function.
You can fix this by writing:
from django.contrib import auth
# ...
def logout(request):
auth.logout(request)
# ...
In addition You do not have to write own logout view - it is given already by default as django.contrib.auth.views.logout.
Problem
Why is this running into an infinite loop, and 'TESTING' never gets printed? It seems like the `logout` function is causing the page to redirect to itself, but the documentation suggests that you can put your own redirect after calling that function. ``` def logout(request): logout(request) print 'TESTING' messages.success(request, 'Logged out.') return HttpResponseRedirect(request.GET['next'] or reverse('home')) ``` Is there another way to log the user out, if this logout function has some hidden redirect functionality? Just took a peek at the source code, nothing suspicious there: ``` def logout(request): """ Removes the authenticated user's ID from the request and flushes their session data. """ request.session.flush() if hasattr(request, 'user'): from django.contrib.auth.models import AnonymousUser request.user = AnonymousUser() ``` I really can't imagine what's causing this.