form.non_field_errors according to form.non_field_errors is not always the best approach, for example, in my case I wanted to display a tooltip, as in this screenshot, next to the field under consideration, using the Django Widget settings .
project / application / templates / template.html
{% render_field field class="form-control is-invalid" data-toggle="tooltip" title=field.errors.as_text %}
Instead of messing around with the template code to pass the HTML title attribute in one piece, I followed @oblalex's advice and wrote my own modified ErrorList class with as_text method without asterisks.
project / application /utils.py
from django.forms.utils import ErrorList class MyErrorList(ErrorList): """ Modified version of the original Django ErrorList class. ErrorList.as_text() does not print asterisks anymore. """ def as_text(self): return '\n'.join(self)
Now that the as_text() function is overwritten, you can pass your MyErrorList class as the error_class argument of your Form or ModelForm or, as in my case, some set of ModelForm forms:
project / application /views.py
from django.forms import formset_factory from .forms import InputForm from .utils import MyErrorList def yourView(request): InputFormSet = formset_factory(InputForm) formset = InputFormSet(error_class=MyErrorList) context = {'formset': formset} return render(request, 'template.html', context)
And now the hint looks like this without an asterisk.
Instead of passing error_class every time you create an instance of the form in your views, you can simply add this single- line line to your form class (see This answer from @Daniel ):
project / application /forms.py
from django import forms from .utils import MyErrorList class InputForm(forms.ModelForm): def __init__(self, *args, row, **kwargs): super(InputForm, self).__init__(*args, **kwargs) self.error_class = MyErrorList