Skip to content

Instantly share code, notes, and snippets.

@laozhu
Created January 4, 2014 02:54
Show Gist options
  • Save laozhu/8250910 to your computer and use it in GitHub Desktop.
Save laozhu/8250910 to your computer and use it in GitHub Desktop.
Class Based Logout View of Django
# -*- coding: utf-8 -*-
from django.core.urlresolvers import reverse
from django.contrib.auth import logout
from django.views.generic import RedirectView
class LogoutView(RedirectView):
"""
A view that logout user and redirect to homepage.
"""
permanent = False
query_string = True
pattern_name = 'home'
def get_redirect_url(self, *args, **kwargs):
"""
Logout user and redirect to target url.
"""
if self.request.user.is_authenticated():
logout(self.request)
return super(LogoutView, self).get_redirect_url(*args, **kwargs)
@DiZiNnEs
Copy link

It's not working in Django 3.1. Can you rewrite it to Django 3.1 ?

@Omid-Asadi
Copy link

It's not working in Django 3.1. Can you rewrite it to Django 3.1 ?

no

@sebatare
Copy link

Why not?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment