Login form error not showing up for wrong username/password combo

367 views
Skip to first unread message

Tom Tanner

unread,
Dec 2, 2017, 12:38:04 AM12/2/17
to Django users
I have this code in my login form.
 {% for field in login_form %}
 
<p>{{ field }}</p>
 
{% if field.errors %}
   
<p class="text-danger">{{ field.errors.as_text|cut:"* "|escape }}</p>
 
{% endif %}
 
{% endfor %}

The user must enter a valid email address in the "username" field. If the user enters a string not formatted like an email, I'll see this error in the `p` tag: "Enter a valid email address."

But if the user enters a bad email/password combo, nothing shows up. In my `views.py`, I have a section that looks something like
if login_form.is_valid:
 
...
else:
 
print login_form.errors

Here's what Django prints to console. "<ul class="errorlist"><li>__all__<ul class="errorlist nonfield"><li>Please enter a correct username and password. Note that both fields may be case-sensitive.</li></ul></li></ul>"

Why does the error print to console but not into my `p` tag?

Constantine Covtushenko

unread,
Dec 2, 2017, 10:59:58 PM12/2/17
to django...@googlegroups.com
Hi Tom,

It seems like your are trying to show error that relates to form rather to particular field.
I see '__all__' key in example from console.

And you did not create any html tag to show such errors on the page.
All I see that you printed just field specific errors.

Probably you should print at the top of your form something like this:
<p>{{ form.non_field_errors }}</>

Regards,
Constantine C.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f4dfcfa5-c687-439e-9e3a-8cb6f0b2c826%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Sincerely yours,
Constantine C

Tom Tanner

unread,
Dec 3, 2017, 9:44:50 PM12/3/17
to Django users
That did it.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages