Django: How to output error_message in paragraph <p> instead of list <li> format -
i have simple form uses sessionwizardview spread on number of pages. below example of 1 of questions.
first_name = forms.charfield(max_length=100, label='what first name?', error_messages={'required': 'please enter first name'})
which renders out
<label for="id_0-first_name">what first name?</label> <ul class="errorlist"> <li>please enter first name</li> </ul> <input id="id_0-first_name" maxlength="100" name="0-first_name" type="text" />
can tell me hwo change error output in <p>
paragraph </p>
format rather <li>
list item </li>
format?
i using django 1.6.2
you can @schillingt suggested , create own error list class.
or, if want handle in template, can use like:
<form method="post" action="/some-view/"> ... other fields, etc. omitted ... <!-- label , form field --> {{ form.first_name.label_tag }} {{ form.first_name }} <!-- output errors --> {% error in form.first_name.errors %} <p>{{ error }}</p> {% endfor %} ... other fields, etc. omitted ... <button type="submit">submit</button> </form>
update
in order in cleanly repeatable way, make template named form-field.html
:
{{ field.label_tag }} {{ field }} <!-- output errors --> {% error in field.errors %} <p>{{ error }}</p> {% endfor %}
then, update main template:
<form method="post" action="/some-view/"> ... other fields, etc. omitted ... {% field=form.first_name %} {% include "form-field.html" %} {% endwith %} ... other fields, etc. omitted ... <button type="submit">submit</button> </form>
you can make updates single form-field.html
template , update of forms, , makes main template bit simpler
Comments
Post a Comment