python口诀

装饰器:单参函数,最里层返回结果

视图函数

视图类: as_view()方法把一个类伪装成了一个视图函数。

cookie-sessionid-token

中间件(链):洋葱模型 

 

 

 

class MagMiddleware1:
    def __init__(self, get_response):
        print(self.__class__.__name__, 'init......')
        self.get_response = get_response

    def __call__(self, request):
        print(self.__class__.__name__,'__call__, before')
        # return HttpResponse(self.__class__.__name__) # 测试点
        response = self.get_response(request)
        print(self.__class__.__name__,'__call__, after')
        return response

    def process_view(self, request, view_func, view_args, view_kwargs):
        print(self.__class__.__name__, 'process_view', view_func.__name__, view_args, view_kwargs)


class MagMiddleware2:
    def __init__(self, get_response):
        print(self.__class__.__name__, 'init......')
        self.get_response = get_response

    def __call__(self, request):
        print(self.__class__.__name__,'__call__, before')
        # return HttpResponse(self.__class__.__name__) # 测试点
        response = self.get_response(request)
        print(self.__class__.__name__,'__call__, after')
        return response

    def process_view(self, request, view_func, view_args, view_kwargs):
        print(self.__class__.__name__, 'process_view', view_func.__name__, view_args, view_kwargs)

 

posted @ 2021-10-19 09:56  豆浆D  阅读(1339)  评论(0编辑  收藏  举报