相关疑难解决方法(0)

如何为Flask中的所有HTTP错误实现自定义错误处理程序?

在我的Flask应用程序中,我可以通过errorhandler为每个错误代码添加装饰器来轻松扩展由单个自定义错误处理程序处理的错误列表,如同

@application.errorhandler(404)
@application.errorhandler(401)
@application.errorhandler(500)
def http_error_handler(error):
    return flask.render_template('error.html', error=error), error.code
Run Code Online (Sandbox Code Playgroud)

但是,此方法需要为每个错误代码使用显式装饰器.有没有办法装饰我的(单个)http_error_handler函数,以便它处理所有 HTTP错误?

python error-handling flask python-decorators

8
推荐指数
3
解决办法
1万
查看次数

标签 统计

error-handling ×1

flask ×1

python ×1

python-decorators ×1