Gelatin Gelatin - 1 year ago 139
CSS Question

How should I style Django validation errors with Bootstrap?

When a form in Django has validation errors, the errors are given in a list with class


Elements can be given an error style with Bootstrap by setting
class="alert alert-error"

What is the best way to combine these, and use Bootstrap's error style for validation errors on Django forms?

Answer Source

In Twitter Bootstrap, input elements are enclosed between "control-group" div or fieldset. So I would do something like this in template

{%for field in form %}
<div class="control-group {%if field.errors %}error{%endif%}">
{# render your field #}
{% endfor %}

Note: In bootstrap, class="alert alert-error" seems to be for alert messages and not for field specific errors.