I have a flask app. On the html file, I have a text input and a submit button, to POST the text input's value to flask, and add it to a database. Works pretty good.
But if I refresh the page, the app inserts the same row for a second time, because the POST method is still set as the text input's value. How do I remove the POST method after one execution?
if request.method == "POST":
caseNumber = request.form["caseNumber"]
myCursor.execute(
"INSERT INTO CASES VALUES ('{}', '', '', '', '')".format(caseNumber))
myConnection.commit()
The usual method is to return a redirection response.
The browser will always follow redirections with a GET response, so even if the user then hits F5 and accepts the "your request may be re-applied" prompt, there's no previous data to post.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.