Skip to content

Instantly share code, notes, and snippets.

@pedroburon
Created January 24, 2012 14:59
Show Gist options
  • Save pedroburon/1670567 to your computer and use it in GitHub Desktop.
Save pedroburon/1670567 to your computer and use it in GitHub Desktop.
bootstrap compatible template for forms in django
{% load i18n %}
<form method="post"
{% if action_url %}action="{{ action_url }}"{%endif %}
{% if form.is_multipart %}enctype="multipart/form-data"{% endif %}>
{% csrf_token %}
<fieldset>
{% if form_legend %}
<legend>{% trans form_legend noop %}</legend>
{% endif %}{# form_legend #}
{% for field in form.hidden_fields %}
{{ field }}
{% endfor %}{# field in form.hidden_fields #}
{% if next %}
<input type="hidden" value="{{ next }}" name="next" />
{% endif %}{# next #}
{% for field in form %}
<div class="clearfix {{ field.errors|yesno:'error,' }}">
{{ field.label_tag }}
<div class="input">
{{ field }}
<span class="help-inline">
{{ field.help_text }}
</span>
{% if field.errors %}
<span class="help-block">
{{ field.errors }}
</span>
{% endif %}
</div>
</div>
{% endfor %}{# field in form #}
<div class="actions">
<input type="reset" class="btn secondary" value="{% trans 'Limpiar' %}" />
<input type="submit" class="btn primary" value="{% trans 'Guardar' %}" />
</div>
</fieldset>
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment