中间件:
class MiddleWare2(MiddlewareMixin): def process_request(self,request): print("MW2 request...........") # return HttpResponse("666!") def process_view(self, request, callback, callback_args, callback_kwargs): # print("callback",callback) # print("callback_args",callback_args) #callback(request) print("MW2 process_view.....") def process_exception(self,request,exception): print("MW2 process_exception...") print(exception) return HttpResponse("<h1 style=‘color:green‘>%s</h1>"%exception) def process_response(self,request, response): # HttpResponse("yuan") print("MW2 response...........") return response
process_request:请求的内容
process_view:用来调用视图函数,如果有返回值回直接执行process_response
process_exception:报错的信息
process_response:响应的内容
执行顺序:
如果只有请求和响应:
加上process_view:
在加上process_exception:
原文地址:https://www.cnblogs.com/fangjie0410/p/8168114.html
时间: 2024-11-09 05:06:45