且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将 Django 表单字段更改为隐藏字段

更新时间:2022-01-17 02:28:40

如果您有自定义模板和视图,您可以排除该字段并使用 {{ modelform.instance.field }} 获得价值.

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.

希望有帮助.