Login

django form template with bootstrap

Author:
youyongsong
Posted:
January 24, 2015
Language:
HTML/template
Version:
Not specified
Score:
0 (after 0 ratings)

required

  • {% load trans%}before using this snippets
  • Add this template filter to your custom templatetags and load it before using this snippets
  • Bootstrap framework
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
<form role="form" action="." method="post"> {% csrf_token %}
  {% if form.non_field_errors %}
  <div class="alert alert-danger">{{ form.non_field_errors|join:"<br \>" }}</div>
  {% endif %}

  {% for field in form %}
  <div class="form-group {% if field.errors %}has-error{% endif %}">
    {{ field.label_tag|add_class:"control-label" }}
    {% if field.help_text %}
    <span class="help-block">{{ field.help_text }}</span>
    {% endif %}
    {% if field.errors %}
    <span class="help-block">{{ field.errors|join:"<br \>" }}</span>
    {% endif %}
    {{ field|add_class:"form-control" }}
  </div>
  {% endfor %}

  <input class="btn btn-success" type="submit" value="{% trans 'submit' %}">
</form>

More like this

  1. Bootstrap Accordian by Netplay4 7 years, 9 months ago
  2. Bootstrap theme for django-endless-pagination? by se210 10 years, 9 months ago
  3. Bootstrap theme for django-endless-pagination? by se210 10 years, 9 months ago
  4. Reusable form template with generic view by roldandvg 10 years, 10 months ago
  5. Pagination Django with Boostrap by guilegarcia 11 years ago

Comments

Please login first before commenting.