如何在Django中列出所有与表单相关的错误? [英] How can I list all form related errors in Django?
本文介绍了如何在Django中列出所有与表单相关的错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经发现了如何在每个字段的基础上但是如前所述,我想列出所有内容。
我使用的方法似乎没有列出所有内容。
{%for form.errors%}
{{error | escape}}
{%endfor%}
谢谢。
解决方案>
除了非字段错误之外,您可以循环遍历所有字段:
Is there a direct way of listing out all form errors in Django templates. I'd like to list out both field and non-field errors and any other form errors.
I've found out how to do this on a per-field basis but as said earlier, I'd like to list out everything.
The method I'm using doesn't seem to list out everything.
{% for error in form.errors %}
{{ error|escape }}
{% endfor %}
Thanks.
解决方案
You could loop over all the field in addition to non-field errors:
- http://docs.djangoproject.com/en/dev/topics/forms/#looping-over-the-form-s-fields
- Short Django snippet: List all Form Errors
这篇关于如何在Django中列出所有与表单相关的错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文