tags:

views:

54

answers:

2

I use clean_fieldname methods in my forms to validate data.

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

(No, I don't include asterisks myself, i just raise ValidationError(u'text') from the clean method)

+3  A: 

The asterisks are added when print the field errors as_text. See django/forms/util.py ErrorList for more detail. It is easier to customize the errors if you print them as_ul instead. The ul will be given a class "errorlist". The Django book has a section on customizing the form errors. Chapter 7 under "Customizing Form Design": http://www.djangobook.com/en/2.0/chapter07/

Mark Lavin
+1, styling the ul with css is the approach to take. My only correction is to point to more recent documentation: http://www.djangobook.com/en/2.0/chapter07/ (see Customizing form design)
celopes
Updated the Django book info. Thanks for pointing that out.
Mark Lavin
i don't usually need styling, i usually need transfer errors via XML and show them to user.
DataGreed
That's strange, that there is no ormal documented way to get just plain text errors without asterisks.
DataGreed
A: 

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

DataGreed