Django Middle

from django.utils.deprecation import MiddlewareMixin

class TimeMiddleware(MiddlewareMixin):
    
    def process_request(self, request):
        # 请求进入middleware执行的第一个方法,可以做一些校验。
        # 可以返回HttpResponse和None
        # 如果返回HttpResponse,接下来只会执行process_response
        return
    def process_view(self, request, func, *args, **kwargs):
        response = func(request)
        return response
    def process_exception(self, request, exception):
        pass
    def process_template_response(self, request, response):
        return response
    def process_response(self, request, response):
        return response

settings.py中的MIDDLEWARE添加新加的类

相关推荐