0
我正在使用标准身份验证表单。它的清洁方法是这样的:奇怪的验证错误消息
def clean(self):
username = self.cleaned_data.get('username')
password = self.cleaned_data.get('password')
if username and password:
self.user_cache = authenticate(username=username, password=password)
if self.user_cache is None:
raise forms.ValidationError(_("Please enter a correct username and password. Note that both fields are case-sensitive."))
elif not self.user_cache.is_active:
raise forms.ValidationError(_("This account is inactive."))
# TODO: determine whether this should move to its own method.
if self.request:
if not self.request.session.test_cookie_worked():
raise forms.ValidationError(_("Your Web browser doesn't appear to have cookies enabled. Cookies are required for logging in."))
return self.cleaned_data
我的登录表单:
但<form method="post" action="{% url django.contrib.auth.views.login %}">
<table>
{% if form.errors %}
<tr class="form-errors">
<td>
<ol>
{% for error in form.errors %}
<li>{{ error }}</li>
{% endfor %}
</ol>
</td>
</tr>
{% endif %}
而不是确认的消息,我得到:
如果用户名和传球不正确或帐户已停用“ 1. __all__
“
如果没有给出密码:”1. password
“
如果没有给出用户名:”1. username
“
如果两者都没有给出: “1. username 2. password
”
没有用户名不正确
编辑消息: 如果我改变
<td>
<ol>
{% for error in form.errors %}
<li>{{ error }}</li>
{% endfor %}
</ol>
</td>
到:
{{form.errors}}
我收到ie即__all__ and beneath it "Account inactive"
。如何获取消息? 任何想法?
现在要选择只采取'__all__'错误:/ – muntu 2010-07-13 19:10:34
编辑我的答案 – crivateos 2010-07-13 19:49:53