Separating your views into multiple files works much the same way as models except for one difference – importing the views in __init__.py isn’t necessary unless you want to type a little less.
Without importing them in __init__, you’ll need to do this:
But if you add them, you can do the following instead:
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.
Class-based views were introduced in Django 1.3 and are very useful. This article discusses how to make use of them along with creating a mixin for requiring the user to be authenticated for a specific view.
I’ve tweaked the example a little bit, redirecting to the login page rather than a 404 and separating the mixin into a separate file.