我正在使用Django 1.2.3.我的网站使用 django.contrib.auth.views.login 具有登录功能.输入正确的用户名和密码后,用户便可以登录.但是, form.has_errors 无法正常工作,即,如果输入的登录凭据不正确,我不会看到错误消息.我的template/registration中的login.html如下:
Im using Django 1.2.3. I have login functionality in my site using django.contrib.auth.views.login. The user is able to login after entering correct username and password. But, form.has_errors is not working i.e. if the login credentials entered are incorrect i dont see the error message. My login.html in templates/registration is as follows :
<html> <head> <title>Login</title> </head> <body> <h1>User Login</h1> {% if form.has_errors %} <p>Your username and password didn't match. Please try again.</p> {% endif %} <form method="post" action="."> {% csrf_token %} <p><label for="id_username">Username:</label> {{ form.username }}</p> <p><label for="id_password">Password:</label> {{ form.password }}</p> <input type="hidden" name="next" value="/" /> <input type="submit" value="login" /> </form> </body> </html>有什么方法可以解决此问题?
Any way to fix this problem?
请帮助谢谢.
推荐答案Form 对象确实具有 errors 属性,请阅读文档以获取更多信息:
A Form object does have an errors attribute, read the docs for more information:
{% if form.errors %} <p>Your username and password didn't match. Please try again.</p> {% endif %}显然, has_errors 在Django 0.95中有效,但至少在1.0以上版本无效(因为它已替换为 errors ).[参考]
Apparently has_errors was valid in Django 0.95 but not from at least 1.0 upwards (as it was replaced with errors). [reference]
更多推荐
form.has
发布评论