Last active
March 1, 2016 15:47
-
-
Save josefmonje/823412367a4e13b771c0 to your computer and use it in GitHub Desktop.
Bootstrap-compatible generic Django form
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% extends 'base.html' %} | |
{% load widget_tweaks %} | |
{% block content %} | |
<form class="form-horizontal" method="POST" enctype="multipart/form-data">{% csrf_token %} | |
<fieldset> | |
<legend>{{ title }}</legend> | |
{% for field in form.visible_fields %} | |
{% if field.errors %} | |
<div class="control-group error"> | |
<label class="control-label">{{ field.label }}</label> | |
<div class="controls">{{ field|add_class:"form-control" }} | |
<span class="help-inline"> | |
{% for error in field.errors %}{{ error }}{% endfor %} | |
</span> | |
</div> | |
</div> | |
{% else %} | |
<div class="form-group"> | |
<label class="control-label">{{ field.label }}</label> | |
<div class="controls">{{ field|add_class:"form-control" }} | |
{% if field.help_text %} | |
<p class="help-inline"><small>{{ field.help_text }}</small></p> | |
{% endif %} | |
</div> | |
</div> | |
{% endif %} | |
{% endfor %} | |
</fieldset> | |
<div class="form-actions"> | |
<button type="submit" class="btn btn-primary">Submit</button> | |
</div> | |
</form> | |
{% endblock %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment