{% load forms %} {{form.media}} {% for title,dict in fieldsets %}
{% endfor %} ### put in forms.py under templatetags ### from django.template import Library from django.forms import ChoiceField from django.forms.fields import FileField register = Library() @register.simple_tag def form_field(form, field, context, tag): """ Usage: form_field form field context 'tag' """ context[tag] = form.__getitem__(field) return '' @register.filter(name='field_value') def field_value(field): """ Returns the value of a form field """ try: value = field.form.initial[field.name] if not value: return '' if isinstance(field.field, ChoiceField): for (val, desc) in field.field.choices: if val == value: return desc return value except: return '' @register.filter(name='is_filefield_instance') def is_filefield_instance(field): return isinstance(field.field, FileField) /***** form_snippet.css ********/ .module { margin-bottom: 5px; background: #ffffff; } .aligned .form_label { display: block; float: left; width: 25%; margin-right: 2%; } .aligned .form_item { display: block; float: left; width: 73%; text-align: left !important; } .aligned .form_item input[type="checkbox"], .aligned .form_item input[type="radio"] { width: auto; float: left; text-align: left; margin-right: 5px; } .aligned .form_item li { width: 33%; float: left; } .form-row { font-size: 11px; padding-bottom: 10px; } .form_label { font-weight: normal !important; color: #666; font-size: 12px; } .form_item input, textarea, select { background: #f8f6f6; border: 1px solid #ccc; color: #666666; width: 98%; } .form_errors { background: #e20019; color: #ffffff; padding: 1px 5px 1px 5px; margin-bottom: 5px; } .form_label_required { color: #e20019; } .form_help_text { font-size: 8px; color: #999999; } .form_submit { text-align: right; } .hidden { display: none; } .clear { clear: both; }