Function view and class view in django

Function view : As the name implies, a view defined in a function is called a function view.

Disadvantages: When the path corresponding to a view provides a variety of different HTTP request methods, it is necessary to write the business logic for judging branches to solve different requests in a function, and the code readability and reusability are not good

 

Class view: use different request methods defined in the class to solve different request methods

Instructions:

from django.views.generic import View

When configuring the route, use the as_view() method of the class view to add

 

 

Guess you like

Origin blog.csdn.net/Growing_hacker/article/details/99729681