1
抓住下面的代码捕获Not Found
例外:无效的路线不被@ app.errorhandler(异常)在烧瓶
@app.errorhandler(404)
def default_handler(e):
return 'not-found', 404
的问题是,当我使用通用errorhandler
它未能赶上404
错误:
@app.errorhandler(Exception)
def default_handler(e):
return 'server-error', 500
暂时我用错误处理程序之一为404
和另一个为其他错误。为什么Not Found
异常不会被第二个捕获?有没有办法使用一个errorhandler
?
编辑:
路线是由两个flask-restful
和@app.route()
手柄。 flask-restful
用于处理资源,@app.route()
用于不适用于资源的用户。
你在用烧瓶吗? – doru
@doru是它用于处理资源路由的模块。当然,除此之外,我还有其他不使用烧瓶的路线,它使用'@ app.route()' – ALH
尝试Flask的最新开发版本'pip install https://github.com/mitsuhiko/flask/压缩包/ master'的。对于如何处理例外的工作进行了大量的工作。这*可能无法在稳定版本中解决。 – davidism