Alex G.P. Alex G.P. - 1 year ago 91
Python Question

Add query string parameter in Flask POST response

I have page with form which. It is working perfect, after form submitted it is replaced with "thank you" message. Initially form is accessible by url

and after submit it has the same URL. I want that after submit url changed to
. I.e. add query string parameter on server side.

I know that I ca do it with redirection, but thus I am losing post-submit rendered content. Also I do not want that if user input
could see post-submit content, i.e. I cannot analyze query string on client side and update HTML. It must be done on server side.

How it could be done?

Answer Source

Short answer: The client should add the query parameter when submitting the form data (e.g. in the action parameter of the form tag).

Explanation: The server is responding to a request to a particular URL. There is no way for the server to "change the URL" of the request. The only thing the server can do is ask the client to send another request to a different URL by returning a redirect. The problem with this approach, as you mentioned, is that the form data will be lost. You could save the form data using cookies or some similar mechanism, but it's much easier to just have the client submit the form to the correct URL in the first place.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download