flask 跨域支持
flask_cors 库添加
from flask_cors import CORS app = Flask(__name__) CORS(app)
# 跨域支持# def after_request(resp): resp.headers['Access-Control-Allow-Origin'] = '*' # resp.setHeader("Access-Control-Allow-Headers", "content-type,XXX"); # resp.setHeader("Access-Control-Allow-Methods", "*"); # resp.setHeader("Access-Control-Allow-Origin", "http://192.168.30.5:8081"); # resp.setHeader("Access-Control-Allow-Credentials", "true"); return resp
flask socket io 跨域支持
添加如下信息
app = Flask(__name__) # cors_allowed_origins 指定允许跨域地址 socketio = SocketIO(app,cors_allowed_origins="http://192.168.30.5:8081") # socketio = SocketIO(app,cors_allowed_origins="*")