Custom renderer for django form fields
Project description
GoodForms — rails-like renderer for your form fields. Provide fully control of filed styles and attributes. It’s not replacement for django.forms.
Installation
Run pip install django-goodforms and add goodforms to INSTALLED_APPS. That’s all.
Usage
The view:
from django.shortcuts import render from django import forms class MyForm(forms.ModelForm): class Meta: model = Client fields = '__all__' def sign_up(request): from = MyForm(initial={'gender': 'male'}) return render(request, 'index.html', {'form': form})
The template:
{% load form_fields %} <form method="post">{% csrf_token %} <div> Your name: {% input form.name placenolder="John Smith" %} </div> <div> You gender: {% radio form.gender label="Male" value="male" %} {% radio form.gender label="Female" value="female" %} </div> {% submit_button %} </form>
Controls
Textfield and Textarea
{% textfield form.title **attrs %} {% textarea form.description **attrs %}
Select
{% select form.country values="ru:Russia,de:Germany" %}
You can use any dict, iterable collection or queryset as values list:
{% select form.county values=queryset_or_collection value_key="code" label_key="title" %}
Tips
You can use any of field without a form class:
{% input "username" required=True %} {% select "city" values="1:New York, 2:London" %}
Settigns
GOODFORMS_XHTML — Enable or disable XHTML syntax (default: False)
GOODFORMS_AUTO_ID — Automatically generate id and for attributes for fields and labels (default: True)
GOODFORMS_ID_PREFIX — Prefix for auto-generated id and for attributes (default: field_)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.