I'm while using django.contrib.auth user management system.

And So I got the registration/place in to the user table/model up and also the login from django.contrib.auth.sights.login up in order to sign in.

However, I can not use django.contrib.auth.sights.logout to logout

I've during my template

<h1>My Account</h1>

<strong> Welcome, titlecapfirst !</strong>

<br /><br />




            <a href="sights.logout %">Logout</a>


            <a href="">Sign Up</a>



            <a href="sights.login %">Login</a>




However always obtain the title and also the logout link because I never really logout after i click the logout button

Here's my web addresses.py section with this:

urlpatterns += designs('django.contrib.auth.views',

    url(r'^login/$', 'login', configurations.ENABLE_SSL , 'login' ),

    url(r'^my_account/$', 'logout', configurations.ENABLE_SSL , 'logout' ),


What am I doing wrong? Note: I'm also running django via apache2 with mod_wsgi


Added Info:

Unsure if the helps however i printed request.session.products within the html and also got

[('_auth_user_backend', 'django.contrib.auth.backends.ModelBackend'), ('_auth_user_id', 9L)]

after i was drenched in as well as once i clicked on the logout button (django.contrib.auth.sights.logout)

Also, I produced:

from django.contrib.auth import logout

def logout_view(request):

    request.session.products = []

    request.session.modified = True


And linked that to some second logout link/button and that i did not logout and also the request.session.products remained just like above after clicking the hyperlink

I believe I am closing in:

In a single of my view functions Used to do:

request.session["fav_color"] = "blue"

request.session.modified = True

after which print in html products which provided

    [('_auth_user_backend', 'django.contrib.auth.backends.ModelBackend'), ('_auth_user_id', 9L)]

with no ('fav_color', 'blue') tuple. Did I actually do a problem again, or perhaps is this proof that my request.session list is not being modified?

K figured it:

url(r'^my_account/$', 'logout', configurations.ENABLE_SSL , 'logout' ),

ought to be

url(r'^logout/$', 'logout', configurations.ENABLE_SSL , 'logout' ),

You must have a logout view using the url pointing to that particular view. Nothing needs to be around the template, simply have django.contrib.auth.logout() for the reason that logout view. Around the new django servers you are able to eaisly logout, but you must do this inside a view, not really a template. Here's an excerpt in the django book:

This situation shows the way you would use both authenticate() and login() inside a view function:

from django.contrib import auth

def login_view(request):

  username = request.Publish.get('username', '')

  password = request.Publish.get('password', '')

  user = auth.authenticate(username=username, password=password)

  if user isn't None and user.is_active:

      # Correct password, and also the user is marked "active"

      auth.login(request, user)

      # Redirect to some success page.

      return HttpResponseRedirect("/account/loggedin/")


      # Show a mistake page

      return HttpResponseRedirect("/account/invalid/")

To log out a person, use django.contrib.auth.logout() in your view. It requires an HttpRequest object and it has no return value:

from django.contrib import auth

def logout_view(request):


  # Redirect to some success page.

  return HttpResponseRedirect("/account/loggedout/")

Make reference to the Django book when it comes to everything http://world wide web.djangobook.com/en/2./chapter14/, I learned from this book.