0
class ContactForm(forms.Form):
    subject = forms.CharField()
    email = forms.EmailField(required = False)
    message = forms.CharField()

蟒蛇壳:

>>> f = ContactForm({'subject': 'Hello'})
>>> f.is_valid()
>>> True

这不是我所期望的。

4

1 回答 1

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.']}
于 2012-08-11T06:15:28.227 回答