pip install flask_cors
from flask_cors import CORS
app = Flask(__name__)
CORS(app, supports_credentials=True)
if __name__ == "__main__":
app.run()
@app.after_request
def af_request(resp):
"""
#请求钩子,在所有的请求发生后执行,加入headers。
:param resp:
:return:
"""
resp = make_response(resp)
resp.headers[‘Access-Control-Allow-Origin‘] = ‘*‘
resp.headers[‘Access-Control-Allow-Methods‘] = ‘GET,POST‘
resp.headers[‘Access-Control-Allow-Headers‘] = ‘x-requested-with,content-type‘
return resp
原文:https://www.cnblogs.com/zwnsyw/p/13341144.html