Class-based views are another way to treat views as Python objects (rather than functions). Since the view is represented as a callable program that receives Web requests and returns Web responses, the view can be defined as a class method. Django provides a view base class for this, and all inherit from the View class, and are used to handle HTTP method scheduling and other common functions.
For some applications, the class-based view is better than the function-based view, which is mainly reflected in the following aspects:
- Organize the code related to the HTTP method in a separate method, such as GET, POST, or PUT.
- Use multiple inheritance to create reusable view classes (also called mixed-in classes).
Regarding class-based views, readers can visit https://docs.djangoproject.com/en/3.0/topics/classbased-views/intro/ to learn more.