Twitter Bootstrap for Django Form

Overview

Django bootstrap form

PyPI version https://travis-ci.org/tzangms/django-bootstrap-form.png?branch=master https://coveralls.io/repos/tzangms/django-bootstrap-form/badge.png?branch=master

Twitter Bootstrap for Django Form.

A simple Django template tag to work with Bootstrap

Installation

Install django-bootstrap-form with pip

$ pip install django-bootstrap-form

Usage

Add "bootstrapform" to your INSTALLED_APPS.

At the top of your template load in our template tags:

{% load bootstrap %}

Then to render your form:

<form role="form">
    <legend>Form Title</legend>
    {% csrf_token %}
    {{ form|bootstrap }}
    <div class="form-group">
      <button type="submit" class="btn btn-primary">Submit</button>
    </div>
</form>

You can also set class="form-vertical" on the form element.

To use class="form-inline" on the form element, also change the "|boostrap" template tag to "|bootstrap_inline".

It is also possible to create a horizontal form. The form class and template tag are both changed, and you will also need slightly different CSS around the submit button:

<form class="form-horizontal">
    <legend>Form Title</legend>
    {% csrf_token %}
    {{ form|bootstrap_horizontal }}
    <div class="form-group">
      <div class="col-sm-10 col-sm-offset-2">
        <button type="submit" class="btn btn-primary">Submit</button>
      </div>
    </div>
</form>

Demo

Checkout this Demo site to see it in action.

Comments
  • Add support for Python 3.6 and Django 2.0

    Add support for Python 3.6 and Django 2.0

    Signed-off-by: Sunil Mohan Adapa [email protected]

    Debian is moving to Django 2.0 soon and django-bootstrap-form needs to work with Django 2.0. Many applications such as FreedomBox using will have problem otherwise.

    Please merge this patch and make a new release so that we can package for Debian immediately. Thank you in advance.

    opened by SunilMohanAdapa 8
  • Bootstrap 3.0

    Bootstrap 3.0

    Hi,

    I changed the code to make it work with bootstrap 3.0.

    Due to a time issue, I only tested simple forms with textarea and text input. I didn't tried formsets and single field rendering, neither the radio and checkbox fields. So you definitively need to check if the code is fully ready for merging.

    I'l try to make more tests next weekend if I find time for it.

    opened by Nivl 7
  • Deprecation warning for Django 1.10: template.render

    Deprecation warning for Django 1.10: template.render

    Catching this deprecation warning when rendering using the template tag.

    /bootstrapform/templatetags/bootstrap.py:80: RemovedInDjango110Warning: render() must be called with a dict, not a Context.
      return template.render(context)
    
    opened by ivanvenosdel 6
  •  __init__.py should use import from meta

    __init__.py should use import from meta

    ahoy there! first of all thanks :+1:

    second: in https://github.com/tzangms/django-bootstrap-form/blob/master/bootstrapform/init.py you could do

    from meta import VERSION
    

    instead of

    from bootstrapform.meta import VERSION
    

    It works just as well, but that way people can put that module wherever

    gracias

    opened by andreasnuesslein 6
  • Why limit to forms?

    Why limit to forms?

    Great idea to keep bootstrap to tags in Django. Might be better than making real BootstrapForm, BootstrapModelForm, etc.

    But why limit it to forms only? You could have tags to include Bootstrap CSS, additional JavaScript (required to make topbar etc work).

    opened by dyve 3
  • Django 1.11.2: context must be a dict rather than Context.

    Django 1.11.2: context must be a dict rather than Context.

    Getting this error in Django 1.11.2. It looks like the previous fix missed a use case. See https://github.com/tzangms/django-bootstrap-form/pull/82/files#r118964036 for more details.

    opened by elynnaie 2
  • 'unicode' object has no attribute 'visible_fields'

    'unicode' object has no attribute 'visible_fields'

    I'm getting error: 'unicode' object has no attribute 'visible_fields'

    Exception Type: AttributeError Exception Value:
    'unicode' object has no attribute 'visible_fields' Exception Location: /Users/nano/code/turpial/kooshi/kenv/lib/python2.7/site-packages/bootstrapform/templatetags/bootstrap.py in render, line 74

    Do you know how could it be fixed?

    opened by andresazp 2
  • Change tag name

    Change tag name

    Hi,

    I propose to change the tag library name and the template tags itself from "bootstrap" to "bootstrapform", as, in my opinion, bootstrap is a little too generic in this case (other bootstrap apps for django already exist)

    cheers Mauro

    opened by bianchimro 2
  • radio field widget

    radio field widget

    First, thanks for the package, saved me a bunch of time.

    It might be nice to support a list of radio fields, which currently come out wrong if you use Django's RadioSelect widget

    I did it using code something like this: https://gist.github.com/2007671

    You might want a different approach, though, looking at your forms.html

    opened by spookylukey 2
  • update for 2.0 breaks 1.3/1.4 compatibility

    update for 2.0 breaks 1.3/1.4 compatibility

    Hi,

    I accidentally updated this library and now my system using bootstrap 1.4 does not display forms the way it used to. Checkboxes with labels that were listed down the page are now jumbled together. Are you going to offer either a versioned pypi package that I can install a specific version of or a setting to support one vs. the other? I can help with either of these if you'd prefer.

    opened by freyley 2
  • Alternate render path dodges Django 1.10 compatibility fix

    Alternate render path dodges Django 1.10 compatibility fix

    Looks like the fix for #77 got thwarted by an indentation error.

    If you take a look at this compatibility code: https://github.com/tzangms/django-bootstrap-form/blob/master/bootstrapform/templatetags/bootstrap.py#L80

    It is actually under the else when it should be covering both cases. This causes the project to be Django 1.10 incompatible under certain circumstances.

    opened by ivanvenosdel 1
  • Support Django 4.0, drop support for older Python & Django versions

    Support Django 4.0, drop support for older Python & Django versions

    • In Django 4.0, widget CheckboxSelectMultiple is a sub-class of RadioSelect causing the former to be rendered as the latter. Fix this by improving the check.

    • Versions of Django < 3.2 are no longer supported[1]. Drop support for them. Continue to support Django 2.2 has this is the version in current Debian stable (and requires no special handling).

    • Versions of Python < 3.7 are no longer supported[2]. Drop support for them.

    • Remove comments and code referring to older versions for simpler code.

    Links:

    1. Django Supported Version: https://www.djangoproject.com/download/

    2. Python Supported Versions: https://devguide.python.org/#status-of-python-branches

    opened by SunilMohanAdapa 0
  • Adding code to run on Powersystem

    Adding code to run on Powersystem

    Hi Here is my contribution to your code, its working good on powersystems.

    Thanks for the code, its working good.

    What do these changes do?

    Added Architecture "ppc64le"

    Are there changes in behavior for the user?

    No

    opened by genisysram 2
  • Add {% bootstrap %} tag that allows custom/grid layout of form fields

    Add {% bootstrap %} tag that allows custom/grid layout of form fields

    This simple patch allows to set grid layout to form fields with the following usage:

    {% bootstrap form %} field1 field2 field3 field4 field5 {% endbootstrap %}

    each line will be renderd as a .row div, and each field will take automatic .col-size

    opened by vitalik 3
  • Fix #59: add_input_classes as filter

    Fix #59: add_input_classes as filter

    add_input_classes should return field to use it as a filter.

    --- a/bootstrapform/templatetags/bootstrap.py
    +++ b/bootstrapform/templatetags/bootstrap.py
    @@ -45,20 +45,21 @@ def bootstrap_horizontal(element, label_cols='col-sm-2 col-lg-2'):
    
         return render(element, markup_classes)
    
     @register.filter
     def add_input_classes(field):
         if not is_checkbox(field) and not is_multiple_checkbox(field) \
            and not is_radio(field) and not is_file(field):
             field_classes = field.field.widget.attrs.get('class', '')
             field_classes += ' form-control'
             field.field.widget.attrs['class'] = field_classes
    +    return field
    

    I would open one-line PR if you want. Thanks.

    opened by codeout 0
Owner
tzangms
tzangms
Tweak the form field rendering in templates, not in python-level form definitions. CSS classes and HTML attributes can be altered.

django-widget-tweaks Tweak the form field rendering in templates, not in python-level form definitions. Altering CSS classes and HTML attributes is su

Jazzband 1.8k Jan 2, 2023
Resolve form field arguments dynamically when a form is instantiated

django-forms-dynamic Resolve form field arguments dynamically when a form is instantiated, not when it's declared. Tested against Django 2.2, 3.2 and

DabApps 108 Jan 3, 2023
Bootstrap 3 integration with Django.

django-bootstrap3 Bootstrap 3 integration for Django. Goal The goal of this project is to seamlessly blend Django and Bootstrap 3. Want to use Bootstr

Zostera B.V. 2.3k Jan 3, 2023
Bootstrap 4 integration with Django.

django-bootstrap 4 Bootstrap 4 integration for Django. Goal The goal of this project is to seamlessly blend Django and Bootstrap 4. Requirements Pytho

Zostera B.V. 980 Dec 29, 2022
Awesome Django Markdown Editor, supported for Bootstrap & Semantic-UI

martor Martor is a Markdown Editor plugin for Django, supported for Bootstrap & Semantic-UI. Features Live Preview Integrated with Ace Editor Supporte

null 659 Jan 4, 2023
Bootstrap 3 integration with Django.

django-bootstrap3 Bootstrap 3 integration for Django. Goal The goal of this project is to seamlessly blend Django and Bootstrap 3. Want to use Bootstr

Zostera B.V. 2.3k Jan 2, 2023
A simple porfolio with Django, Bootstrap and Sqlite3

Django Portofolio Example this is a basic portfolio in dark mode Installation git clone https://github.com/FaztWeb/django-portfolio-simple.git cd djan

Fazt Web 16 Sep 26, 2022
A simple polling app made in Django and Bootstrap

DjangoPolls A Simple Polling app made with Django Instructions Make sure you have Python installed Step 1. Open a terminal Step 2. Paste the given cod

Aditya Priyadarshi 1 Nov 10, 2021
A django model and form field for normalised phone numbers using python-phonenumbers

django-phonenumber-field A Django library which interfaces with python-phonenumbers to validate, pretty print and convert phone numbers. python-phonen

Stefan Foulis 1.3k Dec 31, 2022
MAC address Model Field & Form Field for Django apps

django-macaddress MAC Address model and form fields for Django We use netaddr to parse and validate the MAC address. The tests aren't complete yet. Pa

null 49 Sep 4, 2022
A django model and form field for normalised phone numbers using python-phonenumbers

django-phonenumber-field A Django library which interfaces with python-phonenumbers to validate, pretty print and convert phone numbers. python-phonen

Stefan Foulis 1.3k Dec 31, 2022
This is a sample Django Form.

Sample FORM Installation guide Clone repository git clone https://github.com/Ritabratadas343/SampleForm.git cd to repository. Create a virtualenv by f

Ritabrata Das 1 Nov 5, 2021
Basic Form Web Development using Python, Django and CSS

thebookrain Basic Form Web Development using Python, Django and CSS This is a basic project that contains two forms - borrow and donate. The form data

Ananya Dhulipala 1 Nov 27, 2021
Twitter-clone using Django (DRF) + VueJS

Twitter Clone work in progress ?? A Twitter clone project Table Of Contents About the Project Built With Getting Started Running project License Autho

Ahmad Alwi 8 Sep 8, 2022
Django URL Shortener is a Django app to to include URL Shortening feature in your Django Project

Django URL Shortener Django URL Shortener is a Django app to to include URL Shortening feature in your Django Project Install this package to your Dja

Rishav Sinha 4 Nov 18, 2021
Full control of form rendering in the templates.

django-floppyforms Full control of form rendering in the templates. Authors: Gregor Müllegger and many many contributors Original creator: Bruno Renié

Jazzband 811 Dec 1, 2022
Full control of form rendering in the templates.

django-floppyforms Full control of form rendering in the templates. Authors: Gregor Müllegger and many many contributors Original creator: Bruno Renié

Jazzband 811 Dec 1, 2022
Meta package to combine turbo-django and stimulus-django

Hotwire + Django This repository aims to help you integrate Hotwire with Django ?? Inspiration might be taken from @hotwired/hotwire-rails. We are sti

Hotwire for Django 31 Aug 9, 2022
django-reversion is an extension to the Django web framework that provides version control for model instances.

django-reversion django-reversion is an extension to the Django web framework that provides version control for model instances. Requirements Python 3

Dave Hall 2.8k Jan 2, 2023