class ContactForm(forms.Form):
subject = forms.CharField()
email = forms.EmailField(required = False)
message = forms.CharField()
蟒蛇壳:
>>> f = ContactForm({'subject': 'Hello'})
>>> f.is_valid()
>>> True
这不是我所期望的。
class ContactForm(forms.Form):
subject = forms.CharField()
email = forms.EmailField(required = False)
message = forms.CharField()
蟒蛇壳:
>>> f = ContactForm({'subject': 'Hello'})
>>> f.is_valid()
>>> True
这不是我所期望的。
这不是答案,但我没有看到这种行为。在我的情况下,表格无效。这是来自 django shell,
>>> class ContactForm(forms.Form):
... subject = forms.CharField()
... email = forms.EmailField(required = False)
... message = forms.CharField()
...
>>>
>>>
>>> cf = ContactForm({'subject': "hello"})
>>> cf.is_valid()
False
>>> cf.errors
{'message': [u'This field is required.']}