Python Django表单未引发无效电子邮件的ValidationError

Python Django表单未引发无效电子邮件的ValidationError,python,django,validation,validationerror,Python,Django,Validation,Validationerror,所以我有一个这样的表单,我知道它是有效的,因为保留一些字段为空会在错误字典中给出正确的错误消息,但电子邮件似乎无法正确验证 在表单中.py class NewUserForm(Form): username = UsernameField(required=True) password = CharField(required=True, widget=PasswordInput()) email = EmailField(required=True) 然后在视图中.p

所以我有一个这样的表单,我知道它是有效的,因为保留一些字段为空会在错误字典中给出正确的错误消息,但电子邮件似乎无法正确验证

表单中.py

class NewUserForm(Form):
    username = UsernameField(required=True)
    password = CharField(required=True, widget=PasswordInput())
    email = EmailField(required=True)
然后在视图中.py我有

form = NewUserForm(request.POST)
    if form.is_valid(): 
        # Do stuff
当我输入一封电子邮件(如blah)时,它应该因为没有如中所述抛出“@”(这将导致ValidationError)而失败

(第105行)


我不知道我做错了什么。事实上,即使我没有在电子邮件中输入,它甚至没有声明该字段是必需的

表单对象try/excepts验证错误。如果要显示包含错误的表单,必须执行以下操作:

form = NewUserForm(request.POST)
context = {}
if form.is_valid(): 
    # Do stuff
else:
    # "is_valid()" fills the errors and non_field_errors attributes of the form, you can render it now
    context['myform'] = form
    render_to_response('mytemplate.html', context, context_instance = RequestContext(request))

在模板中,
{{form}}
{{form.as{p}}
{{form.as{ul}}
将以红色显示表单及其错误。

您如何在模板中显示表单?添加打印或日志语句以检查
request.POST
包含的内容。