Django Generic Views: Basic Views
View
The View class provides simple dispatch functionality for all class-based views. Generally, you want to use a subclass of View, instead of inheriting directly from View, but the approach will always be the same. A class-based view is deployed into a URL pattern using the as_view() classmethod:
urlpatterns = patterns('', (r'^view/$', MyView.as_view( answer=42 ) ), )
When the view is invoked, an instance of your class will be created, and any arguments you provide to the as_view method will be set as instance values.
RedirectView
The RedirectView allows you to generically cause an HTTP redirect (301 or 302). The easiest way to use this class is to pass in arguments when defining a URL:
urlpatterns = patterns('', (r'^oldname/(P<id>.*)$', RedirectView.as_view( url="/newname/%{id}s" ) ), )
This will cause a local URL such as /oldname/45 to redirect to /newname/45, which is useful if you've redesigned your URL hierarchy but still need to support the older URIs.
TemplateView
Django Generic Views and Forms
With the 1.3 release of Django, Generic Views have been transformed from a handful of functions to a collection of classes that can be easily sub-classed to override their functionality. While these classes have been given their usual thorough documentation by the Django team, as I investigate them, I intend to document what I discover.
Basic Views
DetailView
ListView
FormView
CreateView
UpdateView
DeleteView