Django set field value after a form is initialized

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

    Something like Nigel Cohen's would work if you were adding data to a copy of the collected set of form data:

    form = FormType(request.POST)
    if request.method == "POST":
        formcopy = form(request.POST.copy())
        formcopy.data['Email'] = GetEmailString()
    

提交回复
热议问题