Django: ModelForm中Meta的fields成员有什么作用?


看了源代码和 官方文档 ,但还是不明白fields到底改变了什么?

django/forms/models.py:

'fields' is an optional list of field names. If provided, only the named fields will be included in the returned dict.


 class MyForm(forms.ModelForm):
    realname = forms.CharField()
    phone = forms.CharField()

    class Meta:
        model = MyUser
        fields = ('phone',)

form = MyForm()
# 照样会输出realname
form.as_table()

python django HTML

爱loli傲娇 11 years, 4 months ago

Your Answer