简体   繁体   English

如何防止浏览器在Django中导航时重新填充表单数据

[英]How to prevent browser from refilling form data when navigating back in Django

I have a django form that submits data to a database. 我有一个django表单,将数据提交到数据库。 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? 有没有办法阻止数据回来?

Add this to your HTML and it will not cache: 将其添加到您的HTML中,它不会缓存:

<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" />

If you want a Django specific answer. 如果你想要一个Django特定的答案。 Try this though the result should be same: 尝试这个虽然结果应该是相同的:

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

暂无
暂无

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

相关问题 在任何浏览器上单击后退按钮时,表单中的数据都会丢失(Django) - lose data in the form when clicking the back button on any browser (Django) 向后导航时将网站缓存到浏览器 - Cache website to browser when navigating back 返回浏览器后,如何以django形式获取字段的现有值? - How do I get the existing value of the fields in a django form when going back in the browser? 数据如何在验证失败时将用户重定向回表单(Python,Django)时如何保留表单? - data How to keep form when user gets redirected back to the form when they fail a validation (Python, Django)? 在长时间运行的AJAX调用中离开页面时,防止Django异常 - Prevent Django exception when navigating away from page during long running AJAX call Django:当表单无效时防止表单重置 - Django: Prevent form from resetting when a form is not valid Django:防止输入无效数据时清除表单字段 - Django: Prevent form fields being cleared when invalid data entered 如何防止用户在 Django 中提交后返回表单(所有表单登录、编辑帖子等)? - how to prevent user from going back to form (all forms login, edit post, etc.) after submission in django? 在django中从服务器发送验证失败时,如何防止表单提交? - how to prevent form submit when validation from server send failed in django? Django:如何将模型表单数据从一个页面传送到另一个页面,然后返回,而无需提交给DB? - Django: How to carry model form data from one page to another, and back, without commiting to the DB?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM