在Django中导航时如何防止浏览器重新填充表单数据 [英] How to prevent browser from refilling form data when navigating back in Django

查看:69
本文介绍了在Django中导航时如何防止浏览器重新填充表单数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Django表单,可将​​数据提交到数据库。成功填写表单并提交数据后,表单将重定向到另一页。但是,当用户单击浏览器上的后退按钮时,数据又回来了。

I have a django form that submits data to a database. When the form has been successfully filled out and the data submitted, the form redirects to another page. However, when the user hits the back button on the browser, the data comes back.

有没有办法防止数据回来?

Is there a way to prevent the data from coming back?

推荐答案

将其添加到HTML并将不会缓存:

Add this to your HTML and it will not cache:

<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate, post-check=0, pre-check=0" /> 
<meta http-equiv="Pragma" content="no-cache" />

如果您需要特定于Django的答案。尝试执行此操作,尽管结果应该相同:

If you want a Django specific answer. Try this though the result should be same:

response = HttpResponse()  # Created a HttpResponse
response['Cache-Control'] = 'no-cache'  # Set Cache-Control Header

这篇关于在Django中导航时如何防止浏览器重新填充表单数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆