0
在我的表格形式,我得到了一个名为Cform
一类的子类,以ConstanceFormCform(ConstanceForm)
重置通过设置变量
在我views.py
class ResetCView(FormView):
template_name = 'c.htm.jinja'
form_class = Cform
model = CModel
def form_valid(self.form):
form.cleaned['C_CODE'] = settings.C_CODE
form.save()
return HttpResponseRedirect(reverse('cview))
在我的模板:
<form method="post" action="{{url('c-reset')}}" name="form">
<button>Reset</button>
</form>
<form method="post" action="{{url('c-view')}}" name="form">
{{ form.as_p}}
</form>
我的问题是它没有更新。表单总是无效的。我只想将表单或其数据库值重置为特定的数据。
你可以发布form.errors。如果它无效,那么我们应该有这个。 – durdenk
表单验证成功后调用 – Sayse
@Sayse,是的,先生,但有没有办法直接保存它。由于我的数据来自默认值。 – Bazinga