iva*_*123 0 django validation templates
我正在尝试验证我的注册表单.我正在使用djanga-registration,它已经具有密码验证功能.
在我的注册表格中,我正在使用此功能:
{% if form.errors %}
{% for field in form %}
<div class="error_message">
{{ field.errors }}
</div>
{% endfor %}
{% endif %}
Run Code Online (Sandbox Code Playgroud)
它显示除密码匹配验证之外的所有错误,即:
def clean(self):
"""
Verifiy that the values entered into the two password fields
match. Note that an error here will end up in
``non_field_errors()`` because it doesn't apply to a single
field.
"""
if 'password1' in self.cleaned_data and 'password2' in self.cleaned_data:
if self.cleaned_data['password1'] != self.cleaned_data['password2']:
raise forms.ValidationError(_(u'no no no'))
return self.cleaned_data
Run Code Online (Sandbox Code Playgroud)
在我的另一个视图中,更改密码,它显示密码匹配验证,但不是我写的那个("不不不"),我认为它显示默认密码.
那么任何想法?
看起来你正确实现了视图,但你的模板没有:
{{ form.non_field_errors }}
Run Code Online (Sandbox Code Playgroud)
http://docs.djangoproject.com/en/dev/topics/forms/#form-objects
"""
Verifiy that the values entered into the two password fields
match. Note that an error here will end up in
``non_field_errors()`` because it doesn't apply to a single
field.
"""
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3226 次 |
| 最近记录: |