当我实例化以下表单并在我的模板中使用它时。我的输入未按要求显示。任何人都知道为什么?
class SampleForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(SampleForm, self).__init__(*args, **kwargs)
# Making name required
self.fields['x'].required = True
self.fields['y'].required = True
self.fields['z'].required = True
self.fields['a'].required = True
class Meta:
model = Sample
fields = ['x','y','z','a' 'email']
模板
<div>
<form>
{{form}}
</form>
</div>