Why does Django's AuthenticationForm return weird str in error message


I’ve recently implemented the Django AuthenticationForm into my project and recognized that the error returns some weird str __all__

Returned error message in the frontend when using a wrong password:

enter image description here

My template

<div class="error-wrapper">
     <div class="errors">{{ form.errors }}</div>

So I took a look into the Django source code to check out the form which doesn’t include __all__ in the error message str:

class AuthenticationForm(forms.Form):
    Base class for authenticating users. Extend this to get a form that accepts
    username/password logins.
    username = UsernameField(widget=forms.TextInput(attrs={'autofocus': True}))
    password = forms.CharField(
        widget=forms.PasswordInput(attrs={'autocomplete': 'current-password'}),

    error_messages = {
        'invalid_login': _(
            "Please enter a correct %(username)s and password. Note that both "
            "fields may be case-sensitive."
        'inactive': _("This account is inactive."),

What do I miss?


The .errors property [Django-doc] returns a dictionary of errors where the keys represent the field where the error occurred, and the value a list of errors. For errors that are not specific to one field, but to two or more fields, it will use __all__. These are thus non-field errors.

When you render a Django from in a template, you can use {{ form.non_field_errors }} to render these, and {{ form.some_field.errors }} to render the errors dedicates to a certain field. You can also iterate over form.non_field_errors and form.some_field.errors to obtain the errors one-by-one, and render these in a different way.

You can thus render non-field errors with:

<div class="error-wrapper">
     <div class="errors">{{ form.non_field_errors }}</div>

Answered By – Willem Van Onsem

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published