简体   繁体   English

Flask:如何删除 request.method == POST

[英]Flask: how to remove request.method == POST

I have a flask app.我有一个 flask 应用程序。 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.在 html 文件上,我有一个文本输入和一个提交按钮,用于将文本输入的值发布到 flask,并将其添加到数据库中。 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.但是如果我刷新页面,应用程序会再次插入同一行,因为 POST 方法仍然设置为文本输入的值。 How do I remove the POST method after one execution?一次执行后如何删除 POST 方法?

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.浏览器将始终使用 GET 响应跟随重定向,因此即使用户随后按 F5 并接受“您的请求可能会被重新应用”提示,也不会发布以前的数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM