Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
128
rated 0 times [  129] [ 1]  / answers: 1 / hits: 6007  / 10 Years ago, sat, march 8, 2014, 12:00:00

So I am trying to use Flask and a Javascript uploader(Dropzone) to upload files and redirect after the upload is complete. Files are getting uploaded fine, but using the traditional redirect in flask:



return (redirect (http://somesite.com))


Does nothing, page does not change. I think this is because of this: The request headers of the files being sent are set to Accept:application/json, and the response headers are being sent in <text/html; charset=utf-8 How can I return a json response and then redirect from it? Just doing



 return (redirect (jsonify(http://somesite.com)))


gives an error:



ValueError: dictionary update sequence element #0 has length 1; 2 is required


I know browsers won't redirect from Json headers anyway. How can I send the url to redirect to from Flask back to my JS app clientside and redirect from there?
I already tested this with a normal HTML form to submit the files and it worked perfectly so I'm pretty sure it is the JSON issue. Thank you.


More From » python

 Answers
4

You can set the mimetype for the response:



response = redirect('http://somesite.com')
response.mimetype = 'application/json'

return response


Or:



return make_response(redirect('http://example.com'), mimetype='application/json')

[#47047] Friday, March 7, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
reed

Total Points: 725
Total Questions: 85
Total Answers: 89

Location: Singapore
Member since Sat, Jul 25, 2020
4 Years ago
;