How to prevent browser from refilling form data wh

2019-03-30 11:27发布

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?

1条回答
神经病院院长
2楼-- · 2019-03-30 11:42

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

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
查看更多
登录 后发表回答