由于浏览器受同源策略的限制,在使用XMLHttpRequest对象进行跨域请求时,请求的时候会出现No 'Access-Control-Allow-Origin' header is present on the requested resource的问题,导致请求失败。
解决办法:

app = Flask(__name__)

# 跨域支持
def after_request(response):
    #JS前端跨域支持
    response.headers['Cache-Control'] = 'no-cache'
    response.headers['Access-Control-Allow-Origin'] = '*'
    return response

app.after_request(after_request)
Last modification:June 10, 2020
If you think my article is useful to you, please feel free to appreciate