Whenever you use a {{ form.field.errors }} tag in a Django template, the validation message that is displayed is always surrounded with a unordered list tag. This is not ideal for me. Am I able to modify the surrounding validation message html for a form from a reusable package?
+3
A:
From the django docs about looping over a form's fields:
{{ field.errors }}
Outputs a<ul class="errorlist">
containing any validation errors corresponding to this field. You can customize the presentation of the errors with a{% for error in field.errors %}
loop. In this case, each object in the loop is a simple string containing the error message.
So for example, to wrap each error in <p>
tags you would do:
{% for error in form.field.errors %}
<p>{{ error|escape }}</p>
{% endfor %}
Alasdair
2009-11-17 00:44:46