Chapter 10, Generic Views, introduced generic views but left out some of the gory details. This appendix describes each generic view along with a summary of options each view can take. Be sure to read Chapter 10, Generic Views, before trying to understand the reference material that follows. You might want to refer back to the Book
, Publisher
, and Author
objects defined in that chapter; the examples that follow use these models. If you want to dig deeper into more advanced generic view topics (like using mixins with the class-based views), see the Django Project website at https://docs.djangoproject.com/en/1.8/topics/class-based-views/.
Most of these views take a large number of arguments that can change the generic view's behavior. Many of these arguments work the same across multiple views. Table C.1 describes each of these common arguments; anytime you see one of these arguments in a generic view's argument list, it will work as described in the table.
Argument |
Description |
---|---|
|
A Boolean specifying whether to display the page if no objects are available. If this is |
|
A list of additional template-context processors (besides the defaults) to apply to the view's template. See Chapter 9, Advanced Models, for information on template context processors. |
|
A dictionary of values to add to the template context. By default, this is an empty dictionary. If a value in the dictionary is callable, the generic view will call it just before rendering the template. |
|
The MIME type to use for the resulting document. It defaults to the value of the |
|
A |
|
The template loader to use when loading the template. By default, it's |
|
The full name of a template to use in rendering the page. This lets you override the default template name derived from the |
|
The name of the template variable to use in the template context. By default, this is |
Table C.1: Common Generic View Arguments