有时候我们在响应的过程中需要对每一个响应做同一件事情时,可以用到flask的延迟请求装饰器
例:对响应头添加统一的配置
@app.after_request
def after_request(response):
response.headers.add('Access-Control-Allow-Origin', 'http://10.141.6.86:8080')
response.headers.add('Access-Control-Allow-Headers', 'Access-Control-Allow-Origin')
response.headers.add('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS')
response.headers.add('Access-Control-Allow-Credentials','true')
return response
参考地址
http://docs.jinkan.org/docs/flask/patterns/deferredcallbacks.html