Twitter Bootstrap for Django Form - A simple Django template tag to work with Bootstrap

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 Title {% csrf_token %} {{ form|bootstrap }}

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 Title {% csrf_token %} {{ form|bootstrap_horizontal }}

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
This is a template tag project for django to calculate in templates , enjoy it

Calculator-Template-Django this is a template tag project for django to calculate in templates , enjoy it Get Started : 1 - Download Source Code 2 - M

null 1 Feb 1, 2022
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
The best way to have DRY Django forms. The app provides a tag and filter that lets you quickly render forms in a div format while providing an enormous amount of capability to configure and control the rendered HTML.

django-crispy-forms The best way to have Django DRY forms. Build programmatic reusable layouts out of components, having full control of the rendered

null 4.6k Jan 7, 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
Projeto onde podes inserir notícias, ver todas as notícias guardas e filtrar por tag. A base de dados usada é o mongoDB.

djangoProject Projeto onde podes inserir notícias, ver todas as notícias guardas e filtrar por tag. A base de dados usada é o mongoDB. packages utiliz

Sofia Rocha 1 Feb 22, 2022
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 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
A starter template for building a backend with Django and django-rest-framework using docker with PostgreSQL as the primary DB.

Django-Rest-Template! This is a basic starter template for a backend project with Django as the server and PostgreSQL as the database. About the templ

Akshat Sharma 11 Dec 6, 2022
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
With Django Hijack, admins can log in and work on behalf of other users without having to know their credentials.

Django Hijack With Django Hijack, admins can log in and work on behalf of other users without having to know their credentials. Docs 3.x docs are avai

null 1.2k Jan 5, 2023