Reputation: 41
I am struggling to redirect to another website completely in flask. I am not sure if it is because of the nature of Flask or because I am using the wrong method. I keep getting the error 'Access to XMLHttpRequest at 'website' from origin '' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. How do I get across this. The code I have written with Python Flask is below. Would I need a status code?:
return redirect('(https://website here)')
Is there any other techniques. I have read about using the webbrowser package but it doesn't seem to work when I deploy my application to heroku. Could someone suggest a way forward. Thanks
@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 THAT SENDS DATA OVER:
new_arr = JSON.stringify(arr);
console.log(new_arr);
$.post("/test", new_arr);
Upvotes: 0
Views: 1122
Reputation: 1644
Yes, you need a status code.
return redirect("http://www.example.com", code=302)
Upvotes: 1