Django1.4 form.is_valid()总是返回True

时间:2012-08-11 02:50:50

标签: django

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

这不是我的预期。

1 个答案:

答案 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.']}