Registry / web-framework / bootstrap-flask

bootstrap-flask

JSON →
library2.6.0pypypi✓ verified 23d ago

Bootstrap-Flask is a collection of Jinja macros for Bootstrap 4 & 5 and Flask. It helps to render Flask-related data and objects to Bootstrap markup HTML more easily, such as Flask-WTF forms, data tables, and pagination. The library is actively maintained, with a recent release of 2.5.0, and typically sees updates to align with new Bootstrap versions and address Python compatibility.

pip install bootstrap-flask
INSTALL
IMPORT
SIG · BOOTSTRAP-FLASK
B
bootstrap-flask
web-frameworkpythonv2.6.0
Install
2.5s avg
Import
517ms
Disk
49MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.6.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.548s · 50.6MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.5s · import 0.486s · 51MB
49MB installed
● package 49MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Bootstrap5
from flask_bootstrap import Bootstrap5
Use this class to initialize Bootstrap 5 support in your Flask application.
Bootstrap4
from flask_bootstrap import Bootstrap4
Use this class to initialize Bootstrap 4 support in your Flask application.
Bootstrap
N/A
from flask_bootstrap import Bootstrap
The generic `Bootstrap` class is deprecated since version 2.0.0 and will be removed in 3.0. You should explicitly use `Bootstrap4` or `Bootstrap5` instead.

This quickstart demonstrates how to set up a basic Flask application, initialize Bootstrap-Flask for Bootstrap 5, define a simple Flask-WTF form, and render it using Bootstrap-Flask's `render_form` macro in a Jinja2 template. It also shows how to include Bootstrap's CSS and JS resources using the helper functions.

from flask import Flask, render_template from flask_bootstrap import Bootstrap5 from flask_wtf import FlaskForm from wtforms import StringField, PasswordField, BooleanField, SubmitField from wtforms.validators import DataRequired, Length import os app = Flask(__name__) app.config['SECRET_KEY'] = os.environ.get('SECRET_KEY', 'a_default_secret_key_for_dev') bootstrap = Bootstrap5(app) class LoginForm(FlaskForm): username = StringField('Username', validators=[DataRequired(), Length(1, 20)]) password = PasswordField('Password', validators=[DataRequired(), Length(8, 150)]) remember = BooleanField('Remember me') submit = SubmitField('Log In') @app.route('/', methods=['GET', 'POST']) def index(): form = LoginForm() if form.validate_on_submit(): # In a real application, process the form data (e.g., login user) return f"Login successful for {form.username.data}! Remember me: {form.remember.data}" return render_template('index.html', form=form) # To run this, save it as app.py and create a 'templates' folder. # Inside 'templates', create 'index.html' with the following content: # # <!doctype html> # <html lang="en"> # <head> # <meta charset="utf-8"> # <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> # <title>Login</title> # {{ bootstrap.load_css() }} # </head> # <body> # <div class="container"> # <h2 class="mt-3">Login</h2> # {% from 'bootstrap5/form.html' import render_form %} # {{ render_form(form) }} # </div> # {{ bootstrap.load_js() }} # </body> # </html> # # Then install dependencies: # pip install flask bootstrap-flask flask-wtf # And run: # export SECRET_KEY='your_strong_secret_key' # or set on Windows/Powershell # flask run
Debug
Known issues
breakingMigration from the older `Flask-Bootstrap` library to `Bootstrap-Flask` requires full uninstallation of `Flask-Bootstrap` before installing `bootstrap-flask`. They cannot coexist in the same environment and use different template paths.
fix
Run `pip uninstall flask-bootstrap` then `pip install bootstrap-flask`. Update template paths from `bootstrap/` to `bootstrap4/` or `bootstrap5/`.
affects: All versions when migrating from `Flask-Bootstrap`
breakingSince version 2.0.0, the generic `Bootstrap` class and the `bootstrap/` template path are deprecated. Users must now explicitly choose and initialize `Bootstrap4` for Bootstrap 4 or `Bootstrap5` for Bootstrap 5.
fix
Replace `Bootstrap(app)` with `Bootstrap4(app)` or `Bootstrap5(app)`. Update Jinja2 template imports from `{% from 'bootstrap/...' %}` to `{% from 'bootstrap4/...' %}` or `{% from 'bootstrap5/...' %}`.
affects: 2.0.0+
deprecatedPython 3.6 support was dropped in version 2.2.0.
fix
Upgrade your Python environment to 3.9 or newer.
affects: 2.2.0+
deprecatedPython 3.7 and 3.8 support was dropped in version 2.5.0.
fix
Upgrade your Python environment to 3.9 or newer.
affects: 2.5.0+
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'flask_bootstrap'
Despite the package being named `bootstrap-flask`, the import path for the Python module is `flask_bootstrap` to maintain compatibility and ease migration from the older `Flask-Bootstrap` library. This error occurs if `bootstrap-flask` is not installed, or if there's an environment issue.
fix
Ensure `bootstrap-flask` is installed correctly using `pip install bootstrap-flask`. If using virtual environments, ensure it's installed within the active environment. The correct import statement is `from flask_bootstrap import Bootstrap5` (or `Bootstrap4` for Bootstrap 4) for the latest versions, or `from flask_bootstrap import Bootstrap` for older versions or if explicitly using the deprecated `Bootstrap` class.
jinja2.exceptions.TemplateNotFound: bootstrap/base.html
This error often occurs when migrating from `Flask-Bootstrap` to `Bootstrap-Flask` because `Flask-Bootstrap` provided a built-in `bootstrap/base.html` template, whereas `Bootstrap-Flask` requires users to create their own base template and explicitly load Bootstrap resources using macros like `bootstrap.load_css()` and `bootstrap.load_js()`. It can also happen if both `Flask-Bootstrap` and `Bootstrap-Flask` are installed, leading to template resolution conflicts.
fix
Create your own `base.html` template in your `templates` folder that includes `{{ bootstrap.load_css() }}` in the `<head>` and `{{ bootstrap.load_js() }}` before the closing `</body>` tag. If both `Flask-Bootstrap` and `Bootstrap-Flask` are installed, uninstall `Flask-Bootstrap` first.
cannot import name 'Bootstrap5' from 'flask_bootstrap'
`Bootstrap5` (and `Bootstrap4`) classes were introduced in `bootstrap-flask` version 2.0 to explicitly support Bootstrap 5 (and Bootstrap 4). This error means you are either using an older version of `bootstrap-flask` that does not expose these classes, or there's a cached or conflicting installation.
fix
Upgrade `bootstrap-flask` to the latest version using `pip install --upgrade bootstrap-flask`. If the issue persists, try `pip uninstall flask-bootstrap bootstrap-flask` and then `pip install bootstrap-flask` to ensure a clean installation. After upgrading, you can import `Bootstrap5` or `Bootstrap4` as needed: `from flask_bootstrap import Bootstrap5`.
jinja2.exceptions.UndefinedError: 'bootstrap_find_resource' is undefined
This error typically arises when there's a conflict between `Flask-Bootstrap` and `Bootstrap-Flask` installations, or when the Bootstrap extension hasn't been properly initialized with your Flask application, leading to Jinja not finding the necessary macros provided by `bootstrap-flask`.
fix
Ensure only `bootstrap-flask` is installed (uninstall `Flask-Bootstrap` if present: `pip uninstall flask-bootstrap`). Verify that `bootstrap-flask` is correctly initialized in your Flask application, usually by `bootstrap = Bootstrap5(app)` (or `Bootstrap4`) after creating your Flask app instance.
from flask_bootstrap import Bootstrap
While `Bootstrap-Flask` uses `flask_bootstrap` as its import package name, directly importing `Bootstrap` without `4` or `5` (e.g., `Bootstrap4` or `Bootstrap5`) is deprecated since version 2.0 and may lead to unexpected behavior or reliance on older Bootstrap versions. The library explicitly moved to versioned imports for clarity and better Bootstrap 4/5 support.
fix
For new projects or when targeting specific Bootstrap versions, use `from flask_bootstrap import Bootstrap5` for Bootstrap 5 or `from flask_bootstrap import Bootstrap4` for Bootstrap 4. Then initialize with `bootstrap = Bootstrap5(app)` or `bootstrap = Bootstrap4(app)`.
Upgrade
Version history
2.6.0latest on PyPI · released Aug 23, 2026
Audit
Dependencies
FlaskrequiredCore web framework integration.
Flask-WTFoptionalCommonly used for form rendering capabilities.
WTFormsoptionalForms generation and validation, often used via Flask-WTF.
Agent activity
22 hits · last 30 days
node
16
OpenAI (training)
1
Resources