django-crispy-forms helps Django applications replace plain, vanilla form output with reusable, styled HTML components. It separates the core form helper from template packs for interface toolkits such as Bootstrap and Tailwind. section 13.3 section 13.3.2
A Bootstrap 5 setup requires the core package, a template pack, and Django configuration:
- Install the main package with `python -m pip install django-crispy-forms` and register `crispy_forms` in `INSTALLED_APPS`. section 13.3.2
- Install the Bootstrap 5 pack with `python -m pip install crispy-bootstrap5` and register `crispy_bootstrap5`. section 13.3.2
- Set `CRISPY_ALLOWED_TEMPLATE_PACKS = "bootstrap5"` and `CRISPY_TEMPLATE_PACK = "bootstrap5"`. section 13.3.2
Choose between quick rendering and fine-grained control in a Django template:
- Apply the `|crispy` filter to a form object instead of `form.as_p` for an opinionated layout and template-pack styling. section 13.3.2
- Use the `{% crispy %}` tag with a form object for greater control over HTML, including IDs, CSS classes, form action, and HTTP method. section 13.3.2
- Add `FormHelper` to a `ModelForm` and pair it with a `Layout` object to control the rendered form. section 13.3.2
Two levels of form styling
A simple template can render a configured form with `{{ form|crispy }}`. When the page needs a custom action, method, IDs, or CSS classes, move to the `{% crispy %}` tag and configure the form through `FormHelper` and `Layout`. section 13.3.2
