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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from app.views.signout import SignOut | |
url(r'^signout/$', SignOut.as_view(), name='signout'), |
views/signout.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |