我有一个中间件,它应该能捕捉500/400个异常并处理它们。但从来没人叫它。我已经将它放在MIDDLEWARE_CLASSES
的开头和结尾,但在引发异常时它仍然不运行:
垂直/中间件.py:
class HandleExceptionsMiddleware(object):
def process_exception(self, request, exception):
print >> sys.stderr, "exception has been raised"
# Get the exception info now, in case another exception is thrown later.
if isinstance(exception, http.Http404):
return self.handle_404(request, exception)
else:
return self.handle_500(request, exception)
py设置
^{pr2}$
以下清单帮助我解决了类似问题:
MIDDLEWARES
中的python点式路径MIDDLEWARES
的底部如果仍然不工作,这意味着其他中间件捕获异常并返回响应,或者其他中间件调用您的视图的顺序不正确或太快。在
None
(显式或隐式)view_func
中的view_func
相关问题 更多 >
编程相关推荐