flask-cors的问题-被CORS策略阻止:对预检请求的响应未通过访问控制检查:它没有HTTP正常状态 [英] issue with flask-cors - blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status

查看:191
本文介绍了flask-cors的问题-被CORS策略阻止:对预检请求的响应未通过访问控制检查:它没有HTTP正常状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是烧瓶的新手,请耐心等待.

I'm a newbie in flask and angular please bear with me.

我一直困扰着有关CORS的问题.我已经应用了不同的代码修复程序以使其正常工作.现在我得到的错误是

I've been stuck with an issue about CORS. I've applied different code fixes just to make it work. Now the error that I am getting is

Access to XMLHttpRequest at 'http://localhost:5000/dashboard/clientscount/2019/2020' from origin 'http://localhost:8080' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.

我认为问题的答案来自于此帖子的已回答问题:

I think the answer to my problem is from the answered question on this post: Has been blocked by CORS policy: Response to preflight request doesn’t pass access control check, specifcally this code

if r.Method == "OPTIONS" {
    w.WriteHeader(http.StatusOK)
    return
}

但这是围棋语言.我在烧瓶里工作.我的问题是如何在烧瓶中制作这个?同样在参考答案中,它表示要响应初始请求,但是我不确定如何继续执行该请求.

but this is in go language. I'm working in flask. my question is how do I make this in flask? also in the reference answer, it says to respond to the initial request but I'm not sure how to proceed with that one.

如果您能为我指出正确的方向或文档,我将非常高兴.

If you could point me in the right direction or docs, I'd gladly appreciate it.

推荐答案

希望这会有所帮助:

如何在烧瓶中启用CORS

您必须先通过运行以下命令来安装flask-cors: pip install -U flask-cors

You have to first install flask-cors by running: pip install -U flask-cors

然后按如下所示导入CORS和Cors来源:

Then import CORS and Cors-origin as follows:

from flask import Flask
from flask_cors import CORS, cross_origin
app = Flask(__name__)
cors = CORS(app)
app.config['CORS_HEADERS'] = 'Content-Type'

@app.route("/")
@cross_origin()

这篇关于flask-cors的问题-被CORS策略阻止:对预检请求的响应未通过访问控制检查:它没有HTTP正常状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆