I am writing a CGI script in python 2.5 and I have run into an issue I cant solve.
My cgi script allows a user to into data into a html form and press refresh and the data gets successfully added. But it has turned out that if a user presses the refresh button on their browser the data that they inputted before gets added again. This is not the behaviour that I am looking for, and as such I would love to be able to redirect a user after a HTTP POST/GET request back to the main page.
This is of course naturally possible, by using the :
print "Location: www.website.here"
line in python. But I cannot do this as I need to be able to store messages between each refresh in order to be able to display information to the user.
These messages are essentially validation error messages, and if a user inputs wrong data and presses submit then my page should reload and print the error messages. I have this side of things working, but if I need to redirect using the above line, then I loose this.
So my question is are there any other possible ways to remove the option to refresh a html page using CGI and python, or am I looking at this all wrong and should I be trying to find a way to store my messages after a HTML redirect?
I assume you actually have two scenarios:
I suppose you can issue a redirect only if the data validates, and display error messages in the other case.
If you have an option to migrate your CGI script to a modern web framework like Flask, Bottle, Django or Pyramid, I suggest you do so. This will give you session state and generally more convenient and modern environment.