Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Format/Overwrite Django Form Error Message?

forms.py

class MyForm(forms.Form):
    no = forms.CharField(error_messages={'required': u'must be xxx')

template.html

{{form.no.error}}

{{form.no.error}} is <ul class="errorlist"><li>must be xxx</li></ul> I want to format {{form.no.error}} to plain text message without any html tags

like image 388
pyth0ner Avatar asked Oct 29 '12 07:10

pyth0ner


1 Answers

You could either just remove the tags:

{{ form.no.errors|striptags }}

Or just access the raw error:

{{ form.no.errors.as_text }}
like image 104
Nathan Villaescusa Avatar answered Oct 21 '22 11:10

Nathan Villaescusa