Make a POST request while redirecting in flask

The redirect function provided in Flask sends a 302 status code to the client by default, and as mentionned on Wikipedia:

Many web browsers implemented this code in a manner that violated this standard, changing
the request type of the new request to GET, regardless of the type employed in the original
request (e.g. POST). [1] For this reason, HTTP/1.1 (RFC 2616) added the new status codes
303 and 307 to disambiguate between the two behaviours, with 303 mandating the change of
request type to GET, and 307 preserving the request type as originally sent.

So, sending a 307 status code instead of 302 should tell the browser to preserve the used HTTP method and thus have the behaviour you’re expecting. Your call to redirect would then look like this:

flask.redirect(flask.url_for('operation'), code=307)

Leave a Comment