Change a Django form field to a hidden field

后端 未结 7 2113
故里飘歌
故里飘歌 2020-12-22 20:21

I have a Django form with a RegexField, which is very similar to a normal text input field.

In my view, under certain conditions I want to hide it from

7条回答
  •  鱼传尺愫
    2020-12-22 21:00

    If you have a custom template and view you may exclude the field and use {{ modelform.instance.field }} to get the value.

    also you may prefer to use in the view:

    form.fields['field_name'].widget = forms.HiddenInput()
    

    but I'm not sure it will protect save method on post.

    Hope it helps.

提交回复
热议问题