Skip to content

Instantly share code, notes, and snippets.

@vaibhav-jain
Created January 24, 2015 17:01
Show Gist options
  • Save vaibhav-jain/9c86d7e32605249a35e4 to your computer and use it in GitHub Desktop.
Save vaibhav-jain/9c86d7e32605249a35e4 to your computer and use it in GitHub Desktop.
render django form errors using bootstrap
<!-- DIV -->
{% if form.errors %}
<div class="alert alert-danger alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
{% for field in form %}
{% if field.errors %}
<span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
<span>{{ field.label }}: {{ field.errors|striptags }}</span><br>
{% endif %}
{% endfor %}
{% for error in form.non_field_errors %}
<span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
<span>Error: {{ error|striptags }}</span>
{% endfor %}
</div>
{% endif %}
<!-- /DIV -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment