flask手动CORS(跨来源资源共享)解决跨域

@app.route("xxxxxx", methods=['POST', 'OPTIONS'])
def case_desc_post():
    """
    提交案例基本信息
    :return:
    """
    print(1111)
    if request.method in ('OPTIONS',):
        return API.resp({}, header={"Access-Control-Allow-Origin": "http://localhost:63342",
                                      "Access-Control-Allow-Methods": "DELETE, GET, HEAD, OPTIONS, PATCH, POST, PUT",
                                      "Access-Control-Allow-Headers": "content-type"})
    if request.method in ('POST'):
        req = request.json
        data = SubCase().db_desc_post(req)
        return API.resp(data, header={"Access-Control-Allow-Origin": "http://localhost:63342",
                                      "Access-Control-Allow-Methods": "DELETE, GET, HEAD, OPTIONS, PATCH, POST, PUT",
                                      "Access-Control-Allow-Headers": "content-type"})

  通常可以用flask_cors模块实现

posted @ 2023-07-14 11:29  残宠魔法袋  阅读(39)  评论(0编辑  收藏  举报