Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
表格.py
class MyForm(forms.Form): no = forms.CharField(error_messages={'required': u'must be xxx')
模板.html
{{form.no.error}}
{{form.no.error}}<ul class="errorlist"><li>must be xxx</li></ul> 我想格式化为{{form.no.error}}没有任何 html 标签的纯文本消息吗
<ul class="errorlist"><li>must be xxx</li></ul>
您可以只删除标签:
{{ form.no.errors|striptags }}
或者只是访问原始错误:
{{ form.no.errors.as_text }}