Composing class-based views

Django views are callables that take requests and return responses. In addition to the function-based views, Django provides an alternative way to define views as classes. This approach is useful when you want to create reusable modular views or combine views of the generic mixins. In this recipe, we will convert the previously shown function-based movie_list view to a class-based MovieListView view.

Getting ready

Create the models, form, and template similar to the previous recipes, Filtering object lists and Managing paginated lists.

How to do it…

  1. We will need to create a URL rule in the URL configuration and add a class-based view. To include a class-based view in the URL rules, the as_view() method is used, as follows: ...

Get Django: Web Development with Python 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.