Render Django forms as described using the twitter bootstrap HTML layout
Project description
Render Django forms using the HTML described by the Bootstrap 3.
Demo
A basic demo is availaible on this sandbox
Install
From PyPI:
pip install django-twitterbootstrap-form
From Source:
python setup.py install
About Bootstrap 2
You can install the 0.2 version of this lib if you still work with old versions of Bootstrap
From PyPI:
pip install django-twitterbootstrap-form==0.2
From Source:
git checkout 0.2 python setup.py install
Requirements
Django>=1.4
django-widget-tweaks==1.3
Configuring
Add widget_tweaks to your INSTALLED_APPS.
Add geelweb.django.twitter_bootstrap_form to INSTALLED_APPS in your settings
Load the tags adding {% load twitter_bootstrap %} in templates
Template filters
twitter_bootstrap
This tag takes 4 optional parameters
layout: Default: “default”. Existing layouts are, default, search, inline, horizontal
size: Default: “sm”. The column sizes. xs, sm, md, lg.
labelcols: Default: 2. Number of columns used for labels
fieldcols: Default: 12 - labelcols. NUmber of columns used for fields.
Example:
{{ form|twitter_bootstrap }}
Advanced usage:
{{ form|twitter_bootstrap:"horizontal,md,3,3" }}
More examples
Default form:
<form role="form"> {{ default_form|twitter_bootstrap }} <button type="submit" class="btn btn-default">Submit</button> </form>
Search form / Navbar form:
<form role="search" class="navbar-form"> {{ search_form|twitter_bootstrap:"search" }} <button type="submit" class="btn btn-default">Search</button> </form>
Inline form:
<form role="form" class="form-inline"> {{ inline_form|twitter_bootstrap:"inline" }} <button type="submit" class="btn btn-default">Sign in</button> </form>
Horizontal form:
<form role="form" class="form-horizontal"> {{ horizontal_form|twitter_bootstrap:"horizontal" }} <div class="form-group"> <div class="col-sm-offset-2 col-sm-10"> <button type="submit" class="btn btn-default">Sign in</button> </div> </div> </form>
Settings
BOOTSTRAP_REQUIRED_SUFFIX
Default: ‘ *’
Required field label suffix.
Widgets
TextInputWithAddon
Form widget to render bootstrap addons.
Takes three optional arguments:
addon
The addon label
placement
the addon placement, append or prepend
size
nothing for a normal size, input-group-lg for a large input and input-group-sm for a small input.
Example:
from geelweb.django.twitter_bootstrap_form.widgets import TextInputWithAddon field = forms.CharField(widget=TextInputWithAddon( addon='.00', placement='append', size='input-group-lg' ))
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Hashes for django-twitterbootstrap-form-0.3.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | f1e263bf4e18d3f2e429ef79d9b379059ac202fd5dc0c86160a4a6482f5b8102 |
|
MD5 | 547227a44bf71bf87e72a2b324ff288c |
|
BLAKE2b-256 | a3ec943c7aabf68654f9b89233326b3f678ac9f59c2c020246d527ea573e35e8 |