Asterisk in django generates verification messages

I use methods clean_fieldnamein my forms to validate data.

I use {{field.errors.as_text}}to output errors to templates. Each error message has an asterisk (the symbol "*") at the beginning of it. Is there a way to display verification messages without asterisks?

(No, I do not turn on the stars myself, I'm just raise ValidationError(u'text')from the method clean)

+3
source share
3 answers

So, I just had to iterate over the errors and print them without as_text ()

+2
source

Another way:

{{ form.username.errors.as_text|cut:"* " }}
+13
source

Asterisks are added when printing field errors as_text. See django / forms / util.py ErrorList for details. It’s easier to configure errors if you print as_ul instead. Ulu will be assigned the "errorlist" class. The Django book has a section on customizing form errors. Chapter 7 in the section "Customizing the layout": http://www.djangobook.com/en/2.0/chapter07/

+3
source

Source: https://habr.com/ru/post/1728466/


All Articles