我访问了一个包含 URL 参数的页面。 例如http://127.0.0.1:5000/?A=ABC123&B=44444&C=hello
当我单击搜索按钮时,使用一些搜索字符串,使用 form method = post,它会进行搜索,但具有相同的 URL,其中包含上次运行的值。 它显示搜索结果,但参数仍然具有上次运行的值 - http://127.0.0.1:5000/?A=ABC123&B=44444&C=hello
我想删除 url 参数。经过我的搜索,URL应该是http://127.0.0.1:5000/
<form method="POST">
<input type="text" name="search">
<button type="submit"><i class="fa fa-search"></i></button>
</form>
我希望搜索按钮应该清除现有的 URL 参数。
最佳答案
据我了解,您可以重定向到请求路径,这将清除网址参数:
@app.route("/search", methods=["POST"])
def search():
... get results ...
redirect(request.path)
关于javascript - 使用 post 方法点击搜索按钮后 URL 不会改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57363280/