Django set field value after a form is initialized

后端 未结 9 1903
陌清茗
陌清茗 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:13

    in widget use 'value' attr. Example:

    username = forms.CharField(
        required=False,
        widget=forms.TextInput(attrs={'readonly': True, 'value': 'CONSTANT_VALUE'}),
    )
    

提交回复
热议问题