标签:错误 es2017 proc sel 返回 http exce 分享 llb
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不会捕获错误
django 中间件process_exception 如果程序有异常就执行
标签:错误 es2017 proc sel 返回 http exce 分享 llb
原文地址:http://www.cnblogs.com/tiantao36/p/7577165.html