def get(self, request, *args,**kwargs): int(sss) return HttpResponse(‘login‘)
注意只要有捕获到异常就直接repon。好处可以直接返回500
class M1(MiddlewareMixin): def process_request(self, request): print(‘m1.process_request‘) def process_view(self, request, callback, callback_args, callback_kwargs): """ 如果有返回值,则不在继续执行,直接到最后一个中间件的response """ print(‘m1.process_view‘, callback) # return HttpResponse(‘Process View返回值‘) def process_response(self,request, response): print(‘m1.prcess_response‘) return response def process_exception(self,request,exception): print(‘m1.process_exception‘) class M2(MiddlewareMixin): def process_request(self, request): print(‘m2.process_request‘) def process_view(self, request, callback, callback_args, callback_kwargs): """ 如果有返回值,则不在继续执行,直接到最后一个中间件的response """ print(‘m2.process_view‘, callback) # return HttpResponse(‘Process View返回值‘) def process_response(self,request, response): print(‘m2.prcess_response‘) return response def process_exception(self,request,exception): print(‘m2.process_exception‘) return HttpResponse(‘500错误‘)
注意如果此时process_view有return 就直接到了reponse不会捕获错误
时间: 2024-11-02 23:59:08