Bootstrap 4 for Django

26.1 · maintenance · verified Thu Apr 16

django-bootstrap4 seamlessly integrates Bootstrap 4 into Django projects, providing template tags and filters for easy rendering of Bootstrap components. As of version 26.1, the library is in maintenance mode, receiving only bug fixes and security updates. This is due to Bootstrap 4 being superseded by Bootstrap 5, and new projects are encouraged to use the dedicated `django-bootstrap5` package.

Common errors

Warnings

Install

Imports

Quickstart

After installing, add 'bootstrap4' to `INSTALLED_APPS` in your Django `settings.py`. In your templates, load the `bootstrap4` template tag library and use `{% bootstrap_css %}` and `{% bootstrap_javascript %}` to include Bootstrap's assets. Forms can be easily rendered using `{% bootstrap_form form %}`.

# settings.py
INSTALLED_APPS = [
    # ...
    'bootstrap4',
    # ...
]

# templates/base.html (or any template using Bootstrap)
{% load bootstrap4 %}

<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    {% bootstrap_css %}
    <title>My Django App</title>
</head>
<body>
    <div class="container">
        <h1>Hello, Bootstrap 4!</h1>
        <form method="post">
            {% csrf_token %}
            {% bootstrap_form form %}
            {% buttons %}
                <button type="submit" class="btn btn-primary">Submit</button>
            {% endbuttons %}
        </form>
    </div>
    {% bootstrap_javascript %}
</body>
</html>

view raw JSON →