【发布时间】:2020-11-20 18:27:31
【问题描述】:
我正在努力完全在烧瓶中重定向到另一个网站。我不确定是因为 Flask 的性质还是因为我使用了错误的方法。我不断收到错误“从源站访问 XMLHttpRequest”已被 CORS 策略阻止:对预检请求的响应未通过访问控制检查:没有“Access-Control-Allow-Origin”标头存在请求的资源。我该如何解决这个问题。我用 Python Flask 编写的代码如下。我需要状态码吗?:
return redirect('(https://website here)')
还有其他技巧吗?我已经阅读了有关使用 webbrowser 包的信息,但是当我将应用程序部署到 heroku 时,它似乎不起作用。有人可以提出前进的道路。谢谢
@app.route('/test', methods=['GET','POST'])
def test():
data = request.get_json(force=True)
dataset=format(data)
model = LinearSVC().fit(tfidf_vectorizer_vectors, y_train)
new_complaint = dataset
new_complaints = ''.join(new_complaint)
print(new_complaints)
values =model.predict(fitted_vectorizer.transform([new_complaints]))
print(values)
labelling=str(values)
print(labelling)
if labelling == "['something']":
return redirect("https://www.google.co.uk/", code=302)
发送数据的 JAVASCRIPT:
new_arr = JSON.stringify(arr);
console.log(new_arr);
$.post("/test", new_arr);
【问题讨论】:
标签: python web flask redirect https