【发布时间】:2014-08-21 22:25:15
【问题描述】:
我的许多烧瓶应用程序都有一些错误处理调用。例如,我的 404 响应是使用 @app.errorhandler 装饰器定义的:
@app.errorhandler(404)
def page_not_found(e):
return jsonify({'status': 'error',
'reason': '''There's no API call for %s''' % request.base_url,
'code': 404}), 404
由于我有大量样板代码,我想将其放在一个公共文件中,并从一个地方继承或导入我的烧瓶应用程序。
是否可以从不同的模块继承或导入烧瓶样板代码?
【问题讨论】:
-
也许你可以写一个样板烧瓶扩展? flask.pocoo.org/docs/extensiondev
-
使用
Blueprint.app_errorhandler:stackoverflow.com/questions/12768825/…
标签: python error-handling flask code-reuse boilerplate