django-中间件
1,首先要写上中间件的原始类.
class MiddlewareMixin(object): def __init__(self, get_response=None): self.get_response = get_response super(MiddlewareMixin, self).__init__() def __call__(self, request): response = None if hasattr(self, 'process_request'): response = self.process_request(request) if not response: response = self.get_response(request) if hasattr(self, 'process_response'): response = self.process_response(request, response) return response
2,继承原始类,增加自己所需要的功能
例如:让有session的对象可以跳过登录功能