A typical use case is to provide the user a sign out button which redirects to another page such as the homepage. The following implements this using the generic RedirectView.
conf/urls.py
from app.views.signout import SignOut | |
url(r'^signout/$', SignOut.as_view(), name='signout'), |
views/signout.py
from django.views.generic.base import RedirectView | |
from django.contrib.auth import logout | |
from django.core.urlresolvers import reverse | |
class SignOut(RedirectView): | |
permanent = False | |
query_string = True | |
def get_redirect_url(self): | |
logout(self.request) | |
return reverse('home') |