Getting a list of errors in a Django form

前端 未结 4 1405
失恋的感觉
失恋的感觉 2020-12-13 13:39

I\'m trying to create a form in Django. That works and all, but I want all the errors to be at the top of the form, not next to each field that has the error. I tried loopin

4条回答
  •  情深已故
    2020-12-13 14:10

    Dannys's answer is not a good idea. You could get a ValueError.

    {% if form.errors %}
          {% for field in form %}
    
               {% for error in field.errors %}
                    {{field.label}}: {{ error|escape }}
               {% endfor %}
    
          {% endfor %}
    {% endif %}
    

提交回复
热议问题