Analysis rest_framework Django source on re_path ( '^ publish /', views.PublishView.as_view ()

re_path('^publish/', views.PublishView.as_view()

 

 1. Method as_view first call request comes class

 

 2. as_view I did not find in their own classes so I can only go looking for parent

 

 3. I like to call my father, because the current APIView inherit View parent. I rewrote the class name of the view class methods, and examples of the parameters. Then we look into the parent View

class APIView(View):

 

 4. It can be seen that View is the parent class returns a view function, and the view inside the closure returns a dispatch call stuff

 

 

 5. You can see request.method.lower is in the list, if I have a package handler, so we need under analysis

is equivalent to self Pubulish, get reflected on the package if no wrong to throw

 

 6. As can be seen heet_method_not_allowed into execution HttpResponseNotAllowed when I saw a different

 

 7. That I print the return value, or class, will trigger __repr__ return value information, it took us a good return

dispatch

 

 8. Return to confirm a good value, handler this time direct execution get, or post 405 is abnormal or throw the wrong information, then returns

 









 

 

Guess you like

Origin www.cnblogs.com/Rivend/p/11802880.html