Skip to main content

Bootstrap 4 integration for django using widget templates that were introduced in Django 1.11.

Motivation

This library is meant to be a drop-in replacement for django-bootstrap4. 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-bs4

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-bs4',
    …
    'django.forms',
    …
]

FORM_RENDERER = 'django.forms.renderers.TemplatesSetting'

Usage

The following template tags are included in the bootstrap4 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-bootstrap4

  • 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 small.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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-bs4-0.0.4.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

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

django_bs4-0.0.4-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

Details for the file django-bs4-0.0.4.tar.gz.

File metadata

  • Download URL: django-bs4-0.0.4.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.3

File hashes

Hashes for django-bs4-0.0.4.tar.gz
Algorithm Hash digest
SHA256 6d269b64c002442b06842f9a913a4bdc5d16ac2cbccf8cfe1bae9a1228a1499c
MD5 646ea26fcca7f251a106c0dff5331be0
BLAKE2b-256 834260936fff3ac236db96566160e3c6118fb7af543e5ac44cb8a6919395a0ca

See more details on using hashes here.

File details

Details for the file django_bs4-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: django_bs4-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 10.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.3

File hashes

Hashes for django_bs4-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 53e9ceee43e8eb135365675b9d8f11eb02983756b67a5fb2c2cb27f3ccb2eb82
MD5 62309e015747392662e1bb160179a356
BLAKE2b-256 ba1884b275c2642b3c6d90d9e5e271398639942a15d1ac0e6eca2e7a8b6c3516

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.0.4 This release

2 files

0.0.3

1 file

0.0.2

1 file

0.0.1

1 file

Supported by

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