开发者

Asterisk in django forms validation messages

I use clean_fiel开发者_运维技巧dname 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)


One more way:

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


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/


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜