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}} <ul class="errorlist"><li>must be xxx</li></ul> I want to format {{form.no.error}} into a text message without any html tags

+4
source share
1 answer

You can simply remove the tags:

 {{ form.no.errors|striptags }} 

Or just access the raw error:

 {{ form.no.errors.as_text }} 
+21
source

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


All Articles