flask-cors模块解决Flask跨域请求Cross-Origin问题
文档:https://flask-cors.readthedocs.io/en/latest/
安装
pip install flask-cors
代码示例
from flask import Flask, jsonify from flask_cors import CORS app = Flask(__name__) CORS(app, supports_credentials=True) @app.route("/data") def data(): products = [ {"name": "香蕉", "price": 20}, {"name": "桔子", "price": 21}, {"name": "橙子", "price": 23}, ] return jsonify(products) if __name__ == '__main__': app.run()
参考