Python编程:flask-cors模块解决Flask跨域请求Cross-Origin问题

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()

参考

【Flask】Flask解决跨域的问题

上一篇:六组案例一举拿下Java实体类 | 带你学《Java面向对象编程》之十三


下一篇:python编程中后缀为py与pyc之间的关系