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_bs4). 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.
  • Concentrates on forms fields and does therefore not include some others features.
  • Uses .form-text.text-danger instead of .invalid-feedback as it does not depend on DOM location. (see also twbs/bootstrap#29439)
  • 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.
  • Does not include field errors at the top of forms as they are already displayed on the fields themselves.
  • Improved ARIA support.
  • 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 Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

django_bs-5.1.0-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_bs-5.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for django_bs-5.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 539566ff5f504984e515724eae684eda9d8fdc30f06add1cd4c46a6a7352540c
MD5 b156dff6de58ac4cf20751bbd5c0f66f
BLAKE2b-256 e7d31a1f83e147e9db158181264544932324289ad8d5378f34f4c88be1c48f6d

See more details on using hashes here.

Supported by

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