DRF基本源码、Resquest及Response对象

1、CBV(Class Base Views)

思路--路由层--as——view()内的闭包函数内存地址
	path('test/',views.TestView.as_view())
	as_view()
    @classonlymethod
    def as_view(cls, **initkwargs):
        #1、内部有view函数、并且有着对外层函数的引用 cls
        # return view 最后返回内层函数名、说明是个闭包函数
        def view(request, *args, **kwargs):
            self = cls(**initkwargs) 
            if hasattr(self, 'get') and not hasattr(self, 'head'):
                self.head = self.get
            self.setup(request, *args, **kwargs)

        view.view_class = cls
        view.view_initkwargs = initkwargs

        # take name and docstring from class
        update_wrapper(view, cls, updated=())

        # and possible attributes set by decorators
        # like csrf_exempt from dispatch
        update_wrapper(view, cls.dispatch, assigned=())
        return view
#2、django任务启动的时候、path('test/',views.TestView.as_view())产生变形
					path('test/',views.view)
views内存地址对应
 def view(request, *args, **kwargs):
            self = cls(**initkwargs)
            if hasattr(self, 'get'<

你可能感兴趣的:(DRF,django,python,rest)