How do I customize form error messages?

80 views
Skip to first unread message

Tom Tanner

unread,
Dec 3, 2017, 9:46:09 PM12/3/17
to Django users
In my login form, I have this code:

 {% if login_form.non_field_errors %}
 
<p class="text-danger">{{ login_form.non_field_errors.as_text|cut:"* "|escape }}</p>
 
{% endif %}

If a user enters the wrong username/password combo, the error reads like this: 'Please enter a correct username and password. Note that both fields may be case-sensitive." I'd like to change this message and other error messages. How do I do this?

Tom Tanner

unread,
Dec 4, 2017, 1:16:51 AM12/4/17
to Django users
Nevermind, I figured out I needed to edit `forms.py`.

My custom login class...

class LoginForm(AuthenticationForm):
 error_messages
= {
 
"invalid_login": _("Incorrect %(username)s/password combo")
 
}
 
# more code here...
}
Reply all
Reply to author
Forward
0 new messages