Skip to main content

simple bootstrap support for django

Project description

Bootstrap forms for Django

Bootstrap integration for django using widget templates.

Motivation

This library is meant to be a drop-in replacement for django-bootstrap5. See below for a list of differences. I really like that library, but it is hard to customize some things because everything is done in python functions. By using widget templates, I hope this library is more flexible.

Installation

Install with pip:

pip install 'django-bs==4.*'  # for bootstrap 4
pip install 'django-bs==5.*'  # for bootstrap 5

After that you have to add it to INSTALLED_APPS. You also need to make sure that the correct FORM_RENDERER is selected and django.forms is in INSTALLED_APPS (after django_bs). This is required so that widget templates can be overwritten:

INSTALLED_APPS = [
    …
    'django_bs',
    …
    'django.forms',
    …
]

FORM_RENDERER = 'django.forms.renderers.TemplatesSetting'

Usage

The following template tags are included in the bootstrap library:

  • bootstrap_field {boundfield} - Render a single field.
  • bootstrap_form {form} - Render errors and all fields for a form. The <form> element itself is not included.
  • bootstrap_messages - Render messages from django.contrib.messages.
  • bootstrap_pagination {page} - Render pagination. A <nav> element is not included.

Please refer to the source code for additional parameters.

Differences to django-bootstrap5

  • Uses widget templates instead of custom renderers. IMHO this makes the code much easier to read and customize. A big downside is that I had to monkey-patch BoundField.as_widget() to include some information that would otherwise not be available in the widget templates.
  • Also overwrites the default form template in Django 4.0 and later so that {{ form }} does the right thing automatically.
  • Concentrates on form fields and does therefore not include some other features.
  • Uses .form-text.text-danger instead of .invalid-feedback as it does not depend on DOM location. (see also twbs/bootstrap#29439)
  • Uses Django's required_css_class which is defined on the Form class and added to the <label>.
  • Does not use .is-valid because I find it confusing with server-side rendering.
  • Does not include dismiss-buttons for alerts to avoid depending on JavaScript.
  • Non-field errors are styled as alerts.
  • Improved accessibility.
  • You will have to load bootstrap yourself.
  • No configuration.

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

django_bs-5.4.0.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_bs-5.4.0-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

Details for the file django_bs-5.4.0.tar.gz.

File metadata

  • Download URL: django_bs-5.4.0.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for django_bs-5.4.0.tar.gz
Algorithm Hash digest
SHA256 58bfdeb1f1adaae1ed7b6a44bc22462de2b430d6a0115ebd66aa018c8367b6aa
MD5 7084f3c1d96dafd4e972c8673b619f8d
BLAKE2b-256 6b6253bf12398de88651df5a9b3af7d1b2f900ce263538bc586b66a5e4537def

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_bs-5.4.0.tar.gz:

Publisher: main.yml on xi/django-bs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file django_bs-5.4.0-py3-none-any.whl.

File metadata

  • Download URL: django_bs-5.4.0-py3-none-any.whl
  • Upload date:
  • Size: 11.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for django_bs-5.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 971285792d2abb2af2afa28f596e96a002951b998b1672858112b9347edfdd60
MD5 933064f4ada2e6a860cb1d95626c7ce5
BLAKE2b-256 cdc705c5bf8efc64a0eb5a6146f06f2d98fee126aad647c9b9e1ca323aa4ab8c

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_bs-5.4.0-py3-none-any.whl:

Publisher: main.yml on xi/django-bs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page