Will & Skill Developers

Will & Skill Developers


Thoughts, snippets and ideas from the team at Will & Skill AB, Stockholm.

Faisal Mahmud
Author

“The mind is not a vessel to be filled, but a fire to be kindled.” ― Plutarch

Share


Pretty Bootstrap 2.3 form with Django forms

Faisal MahmudFaisal Mahmud

An HTML include for Django that automatically generates a pretty Bootstrap form.

You will need to include bootstrap.css and responsive.css (if you want the form to be responsive) in your HTML document.

NOTE: This works with Bootstrap 2.3, a newer template for Bootstrap 3 will be published soon!


{% comment %}
# ----------------------------------------------------------------------
# EXAMPLE
# ----------------------------------------------------------------------
# {% with submit_value='Register' %}
#    {% include 'controlpanel/includes/vertical_form_generic.html' %}
# {% endwith %}
# ----------------------------------------------------------------------
{% endcomment %}

{% if form %}
    {% csrf_token %}
    {% if form.non_field_errors %}
        {% for error in form.non_field_errors %}
            <div class="row-fluid">
                <div class="span8 alert alert-error">{{ error }}</div>
            </div>
        {% endfor %}
    {% endif %}
    {% for field in form %}
        <div class="row-fluid">
            <div class="span12">{{ field }}</div>
        </div>
        {% if field.errors %}
            {% for error in field.errors %}
                <div class="row-fluid">
                    <div class="span12 alert alert-error">{{ error }}</div>
                </div>
            {% endfor %}
        {% endif %}
    {% endfor %}
    <div class="row-fluid">
        <div class="span12">
            <input type="submit" value="{% if submit_value %}{{ submit_value }}{% else %}Submit{% endif %}" class="btn btn-success btn-block">
        </div>
    </div>
{% endif %}
Faisal Mahmud
Author

Faisal Mahmud

“The mind is not a vessel to be filled, but a fire to be kindled.” ― Plutarch

Comments