17.3 Why Use Classes for Generic Views?

A generic view is a view that provides behavior but that cannot work unless a developer configures it. A GCBV is a generic view that is also class-based. However, Django does not supply generic function views (anymore).

Django introduced the concept of generic views even before version 1.0. At the time, all of the views were functions. The problem with functions as generic views is that they are difficult to override. To demonstrate, we can build our own generic function view.

Our model_list() view, shown in Example 17.20, is built to replace basic listing behavior, as exhibited by TagList or StartupList. As with our custom DetailView, we derive all of the necessary information from the _meta attribute ...

Get Django Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.