Django set field value after a form is initialized

后端 未结 9 1941
陌清茗
陌清茗 2020-12-12 14:50

I am trying to set the field to a certain value after the form is initialized.

For example, I have the following class.

class CustomForm(forms.Form)         


        
9条回答
  •  情书的邮戳
    2020-12-12 15:02

    To throw yet another way into the mix: this works too, with a bit more modern notation. It just works around the fact that a QueryDict is immutable.

    >>> the_form.data = {**f.data.dict(), 'some_field': 47}
    >>> the_form['some_field'].as_widget()
    ''
    

提交回复
热议问题