CBV基于反射实现根据请求方式不同,执行不同的方法。
大体流程为:url -> view方法 -> dispatch方法(反射执行其他:GET/POST/DELETE/PUT)
其中url ->view方法,本身父类View中的as_view(cls, **initkwargs)中又有一个view(),并且as_view()返回的就是view()
@classonlymethod
def as_view(cls, **initkwargs):
"""Main entry point for a request-response process."""
for key in initkwargs:
if key in cls.http_method_names:
raise TypeError("You tried to pass in the %s method name as a "
"keyword argument to %s(). Don't do that."
% (key, cls.__name__))
if not hasattr(cls, key):
raise TypeError("%s() received an invalid keyword %r. as_view "
"only accepts arguments that are already "
"attributes of the class." % (cls.__name__, key))
def view(request,