form.has

编程入门 行业动态 更新时间:2024-10-17 10:36:10
本文介绍了form.has_errors标签不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用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

本文发布于:2023-11-26 20:42:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1635125.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:form

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!