简体   繁体   English

返回浏览器后,如何以django形式获取字段的现有值?

[英]How do I get the existing value of the fields in a django form when going back in the browser?

I'm trying to understand how django populates the data in a form when I go back in a browser 我想了解当我在浏览器中返回时django如何填充表格中的数据

In the debugger when I go back in the browser it generates a GET request, not a POST and so the form is not bound and has no self.data . 在调试器中,当我返回浏览器时,它将生成GET请求,而不是POST,因此该表单未绑定且没有self.data

How do I get the existing values of the fields in a django form when going back in the browser? 返回浏览器后,如何以django形式获取字段的现有值?

(note I am using session with database backend) (请注意我正在使用数据库后端会话)

While creating the form use initial data. 创建表单时,请使用初始数据。

data = { 'field_1': 'value'}
my_form = MyForm(initial=data)

The error is in the question. 错误出在问题上。 The data is coming from the browser cache not the backend. 数据来自浏览器缓存而不是后端。

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

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