Django。如何在页面重新加载后保留表单字段中的数据?

时间:2022-10-15 19:23:08

When i submit my form it clears my form field values. I tried to set the initial data in the form constructor, but ut says that the form object IS NOT CALLABLE

当我提交表单时,它会清除我的表单字段值。我试图在表单构造函数中设置初始数据,但是ut表示表单对象不是CALLABLE

form_class = self.get_form_class()
self.form = self.get_form(form_class(initial = get_data))
context = self.get_context_data(object_list=self.object_list, form=self.form, collapse=collapse)
return self.render_to_response(context)

1 个解决方案

#1


0  

I have figured it out Class-based views firstly need to be declared and after that constructor can be called self.form = self.get_form(form_class) self.form = form_class(request.GET)

我已经想到了基于类的视图首先需要声明,之后构造函数可以被称为self.form = self.get_form(form_class)self.form = form_class(request.GET)

#1


0  

I have figured it out Class-based views firstly need to be declared and after that constructor can be called self.form = self.get_form(form_class) self.form = form_class(request.GET)

我已经想到了基于类的视图首先需要声明,之后构造函数可以被称为self.form = self.get_form(form_class)self.form = form_class(request.GET)