Skip to content Skip to sidebar Skip to footer

How To Redirect From A JSON Response?

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 traditiona

Solution 1:

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')

Solution 2:

If you are using AJAX calls, then you need to return the destination location in the JSON response and then set the value of window.location.href to this in your JS code.


Post a Comment for "How To Redirect From A JSON Response?"