Django Bootstrap 5

26.2 · active · verified Thu Apr 16

django-bootstrap5 is a Django app that provides Bootstrap 5 integration for Django projects, offering a collection of template tags and filters to seamlessly blend Django forms, messages, and other components with Bootstrap 5. It is actively maintained and considered production-ready, with frequent releases to keep up with Bootstrap and Django updates.

Common errors

Warnings

Install

Imports

Quickstart

After installation, add `django_bootstrap5` to your `INSTALLED_APPS`. In your Django templates, load the `django_bootstrap5` library using `{% load django_bootstrap5 %}`. Include `{% bootstrap_css %}` in your `<head>` and `{% bootstrap_javascript %}` before the closing `</body>` tag to load Bootstrap's CSS and JS. You can then use template tags like `{% bootstrap_form form %}` to render forms easily.

# settings.py
INSTALLED_APPS = [
    # ...
    'django.contrib.staticfiles',
    'django_bootstrap5',
    # ...
]

# myapp/templates/myapp/base.html (or any template using Bootstrap)
{% load django_bootstrap5 %}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>My Django App</title>
    {% bootstrap_css %}
</head>
<body>
    <div class="container">
        <h1>Hello Bootstrap 5!</h1>
        <form method="post" class="form">
            {% csrf_token %}
            {% bootstrap_form form %}
            {% bootstrap_button button_type="submit" content="Submit" %}
        </form>
    </div>
    {% bootstrap_javascript %}
</body>
</html>

view raw JSON →