Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django logout problem

Here is the problem I am facing with the Django Authenetication

  1. Access a page that requires a login.
  2. Logout (accessing django.contrib.auth.logout)
  3. Access the original login-protected page. You are still logged in

Any ideas how to solve the problem?

MY Django Session Settings are

SESSION_EXPIRE_AT_BROWSER_CLOSE = True SESSION_COOKIE_AGE = 3600

Thanks, Sujit

like image 372
SystemMatrix Avatar asked Jan 15 '10 21:01

SystemMatrix


2 Answers

Basically, this should work:

from django.contrib.auth import logout

def logout_view(request):
    logout(request)
    # Redirect to a success page.

Could you clarify by posting your view if it's not something like this?

like image 100
jbochi Avatar answered Nov 20 '22 06:11

jbochi


In Django 1.4.* I've had problems with the logout() function. It simply wasn't logging out my users.

Now I'm just using the contributed view to logout users and it works perfectly. Simply add this to your root urls.py file if you don't want to do anything else special:

(r'^logout/$', 'django.contrib.auth.views.logout', {'next_page': '/login'}),

and you'll be good to go.

Happy Djangoing.

like image 40
Craig Labenz Avatar answered Nov 20 '22 05:11

Craig Labenz