Good evening, is it possible to change how ValidationError is displayed? I noticed that django creates a <ul>
tag and inside it a <li>
tag with the error. Can I change the way this is done? And if I wanted to change the class of these elements, how would I?
I'm trying to do this in django authentication, I took a look at the source code and django.contrib.auth.forms in the form AuthenticationForm (only part related to displaying the error) looks like this:
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."),
def clean(self):
username = self.cleaned_data.get('username')
password = self.cleaned_data.get('password')
if username is not None and password:
self.user_cache = authenticate(self.request, username=username, password=password)
if self.user_cache is None:
raise self.get_invalid_login_error()
else:
self.confirm_login_allowed(self.user_cache)
return self.cleaned_data
def get_invalid_login_error(self):
return forms.ValidationError(
self.error_messages['invalid_login'],
code='invalid_login',
params={'username': self.username_field.verbose_name},
)