class ContactForm(forms.Form):
subject = forms.CharField()
email = forms.EmailField(required = False)
message = forms.CharField()
python shell:
>>> f = ContactForm({'subject': 'Hello'})
>>> f.is_valid()
>>> True
这不是我的预期。
答案 0 :(得分:1)
这不是答案,但我没有看到这种行为。在我的情况下,表格无效。 这是来自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.']}