开发者

form.has_errors tag not working

开发者 https://www.devze.com 2023-02-02 14:40 出处:网络
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

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">User开发者_JS百科name:</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?

Please Help Thank You.


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 %}

Apparently has_errors was valid in Django 0.95 but not from at least 1.0 upwards (as it was replaced with errors). [reference]

0

精彩评论

暂无评论...
验证码 换一张
取 消