from flask import Flask, make_response, jsonify app = Flask(__name__) # 封装一个response函数,“*”代表响应头里允许全部域名访问 def make_new_response(data): res = make_response(jsonify({'code': 0, 'data': data})) res.headers['Access-Control-Allow-Origin'] = '*' res.headers['Access-Control-Allow-Method'] = '*' res.headers['Access-Control-Allow-Headers'] = '*' return res # 接口的response,将数据传入make——new-response @app.route("/test") def test(): res = "{'no':'dddd'}" return make_new_response(res) if __name__ == "__main__": app.run(debug=True)