crispy-bootstrap5
Bootstrap 5 template pack for django-crispy-forms, with floating labels, accordions, and switches.
Repository Health
Technical Analysis
crispy-bootstrap5 provides the Bootstrap 5 template pack for django-crispy-forms, letting Django developers render forms with Bootstrap 5 markup by setting a single settings flag. It ships full HTML templates for every crispy-forms layout object — fields, rows, columns, accordions, tabs, formsets, and buttons — so forms match Bootstrap 5’s class conventions without hand-writing template overrides.
Beyond the standard template swap, the package adds a handful of Bootstrap 5-specific layout objects: FloatingField for floating labels, BS5Accordion for accordion groups with flush and always-open behavior, and Switch for toggle-style checkboxes. It tracks new Django and Bootstrap releases closely, with CI running against multiple Python and Django versions to catch breakage from either side of that boundary.
What You Get
- Bootstrap 5 templates for every crispy-forms layout object (fields, rows, columns, formsets, tabs, accordions, buttons)
- FloatingField layout object for Bootstrap 5 floating labels
- BS5Accordion with
flushandalways_openoptions for accordion groups - Switch layout object rendering toggle-style checkboxes
- CI-tested compatibility matrix across supported Python and Django versions
Common Use Cases
- Rendering Django forms with Bootstrap 5 styling by setting CRISPY_TEMPLATE_PACK
- Adding floating-label inputs to a Bootstrap 5 form
- Building collapsible accordion sections inside a crispy-forms Layout
- Rendering boolean fields as Bootstrap 5 switches instead of plain checkboxes
Under The Hood
Architecture
The entire package is a template pack plus three small layout-object subclasses (FloatingField, BS5Accordion, Switch in crispy_bootstrap5/bootstrap5.py) built on top of django-crispy-forms’ own Field and Accordion base classes. There is no application logic, no models, no views — the design surface is a directory of Django templates mirroring crispy-forms’ expected template layout, resolved at render time via the CRISPY_TEMPLATE_PACK setting and each layout object’s template class attribute. Because the resolution contract (how crispy-forms locates and renders templates for a given pack name) lives entirely in the external django-crispy-forms library, the only thing that could break this package’s core abstraction is a change to that upstream contract — a clean, correctly decoupled dependency direction for what is inherently a thin adapter.
Tech Stack Pure Python and Django templating with no other runtime dependencies beyond django>=5.2 and django-crispy-forms>=2.3. Packaging uses a PEP 621 pyproject.toml with setuptools as the build backend and a dynamic version sourced from crispy_bootstrap5.version. Releases publish to PyPI via GitHub Actions using trusted OIDC publishing, triggered on GitHub release creation. Testing and linting run through tox, which drives a matrix across Python 3.10-3.14, Django 5.2/6.0/6.1, and both the latest released and main-branch versions of django-crispy-forms.
Code Quality
The test suite (116 test functions across test_tags.py, test_form_helper.py, test_layout.py, and test_layout_objects.py) uses pytest and pytest-django, asserting rendered form HTML against golden-file fixtures stored under tests/results/. Tests run with -W error on Deprecation and PendingDeprecation warnings, surfacing upstream breakage early rather than letting it pass silently. Linting is enforced through a dedicated tox environment running black, isort, and flake8, mirrored locally via .pre-commit-config.yaml, and CI (GitHub Actions) runs the full matrix plus a separate publish workflow. There is no static type checking anywhere in the codebase, though the surface area being typed (three small classes plus templates) is limited.
API Design The public API is intentionally minimal: most users need zero new imports at all, since setting CRISPY_TEMPLATE_PACK = “bootstrap5” is enough to get Bootstrap 5 rendering out of the box. Users who want the extra behaviors import one of three layout-object subclasses and drop them directly into an existing crispy-forms Layout, with no additional configuration. The README documents every layout object with a runnable snippet, and the CHANGELOG records precisely which Django or Bootstrap version triggered which template change (for example, the aria-describedby accessibility fix added for Django 5.2 support). The pattern itself closely follows sibling template packs like crispy-bootstrap4 rather than introducing a new integration approach, so it is a well-executed adapter rather than a novel one.