0

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()
deceze
  • 510,633
  • 85
  • 743
  • 889
Rohalt
  • 147
  • 1
  • 2
  • 13

1 Answers1

1

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.

AKX
  • 152,115
  • 15
  • 115
  • 172