如果我的Form类和fields
中有3个字段,我只设置了一个字段,在我的html页面上仍然会有3个字段。
示例:
class CategoryForm(forms.ModelForm):
name = forms.CharField(max_length=128,
help_text='Please enter the category name.')
views = forms.IntegerField(initial=0)
likes = forms.IntegerField(initial=0)
slug = forms.CharField(widget=forms.HiddenInput(), initial=0)
class Meta:
model = Category
fields = ('name',)
所以fields
变量并不隐藏任何内容?
答案 0 :(得分:1)
“生成的Form类将为字段属性中指定的每个模型字段按指定顺序设置一个表单字段。”
如果要隐藏字段,请使用
for(String NewlineData : headerLists.get(j).getText().split("\n"))
System.out.println(Hotelid + NewlineData + " | ");
}
我强烈建议您查看文档:
https://docs.djangoproject.com/en/1.8/topics/forms/modelforms/#selecting-the-fields-to-use