Skip to main content

Django Twitter Bootstrap Form

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

0.4.0

  • Django >= 1.8

  • django-widget-tweaks == 1.3

0.3.3

  • Django >= 1.4, <= 1.8

  • 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

TextInputWithButton

Widget to render bootstrap button addons.

Takes one optional argument:

btn_attrs

A dictionary containing HTML attributes to be set on the button. The button can be appened or prepended to the input field using the placement key set to append or prepend:

from geelweb.django.twitter_bootstrap_form.widgets import TextInputWithButton

field = forms.CharField(widget=TextInputWithButton(btn_attrs={
    'label': 'search',
    'type': 'submit',
    'placement': 'append'
}))

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'
))

Metadata

Release files for django-twitterbootstrap-form 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-twitterbootstrap-form 0.4.0
File Size Uploaded Provenance Actions
django-twitterbootstrap-form-0.4.0.tar.gz 6.5 kB Without provenance Details for django-twitterbootstrap-form-0.4.0.tar.gz

Release files / django-twitterbootstrap-form-0.4.0.tar.gz

Download URL django-twitterbootstrap-form-0.4.0.tar.gz
Size 6.5 kB
Tags Source
SHA-256 checksum
How to use checksums
c4bf48d5dbf3894035605a7b05f8b4bd494808b57ef4b19a2924c857d591b501
BLAKE2b-256 checksum
How to use checksums
dcba302f738da0e0ae4556b51ce35bcb07de3071e7611b062d9e531b3b17cf5c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for django-twitterbootstrap-form 0.4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page