Search code examples
django-templatesdjango-sessions

log user out from template file in django


I want to add a logout href in my admin.html like:

<a href="/panel/">Log out</a>

What can I do to destroy the session when a user is redirected to /panel/ by clicking that 'Log out' link? What are the session variables to use in template files?

thank you


Solution

  • In your view do something like this

    #views.py
    from django.contrib.auth import logout as auth_logout
    
    def logout(request):
        response = auth_logout(request)
        return HttpResponseRedirect('http://yourdomain.com')
    
    #urls.py
    from django.conf.urls.defaults import *
    
    urlpatterns = patterns('',
        url(r'^panel/$', 'views.logout', name='logout'),
    )