Registry / web-framework / flask-bootstrap

flask-bootstrap

JSON →
library3.3.7.1pypypi✓ verified 86d ago

Flask-Bootstrap is an extension that packages Twitter Bootstrap (version 3.3.7.1) into a Flask application, providing template macros and resources without requiring boilerplate code. It simplifies the integration of Bootstrap's CSS and JavaScript components into Flask projects. The project's last release was in January 2017, and it is primarily designed for Bootstrap 3 and has Python 2 classifiers.

pip install flask-bootstrap
INSTALL
IMPORT
SIG · FLASK-BOOTSTRAP
F
flask-bootstrap
web-frameworkpythonv3.3.7.1
Install
4.1s avg
Import
620ms
Disk
24MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v3.3.7.1 · 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.920 runs
installs and imports cleanly · install 0.0s · import 0.645s · 25.7MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 4.1s · import 0.595s · 26MB
24MB installed
● package 24MB
Code
Verified usage

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

Bootstrap
from flask_bootstrap import Bootstrap
from flask_bootstrap import FlaskBootstrap
The class is simply `Bootstrap`.

Initialize the Flask app and the Bootstrap extension, then create a simple route that renders a template extending `bootstrap/base.html` to inherit Bootstrap's styling and scripts. The `SECRET_KEY` is required by Flask for certain functionalities (e.g., flashed messages).

from flask import Flask, render_template from flask_bootstrap import Bootstrap import os app = Flask(__name__) app.config['SECRET_KEY'] = os.environ.get('FLASK_SECRET_KEY', 'a_secret_key_for_dev') bootstrap = Bootstrap(app) @app.route('/') def index(): return render_template('index.html') # To run this, save as app.py and create templates/index.html: # # templates/index.html # {% extends "bootstrap/base.html" %} # {% block title %}My Flask-Bootstrap App{% endblock %} # # {% block content %} # <div class="container"> # <h1>Hello, Flask-Bootstrap!</h1> # <p>This is a basic Flask application with Bootstrap 3 via Flask-Bootstrap.</p> # <button type="button" class="btn btn-primary">Primary button</button> # </div> # {% endblock %} if __name__ == '__main__': app.run(debug=True)
Debug
Known issues
breakingFlask-Bootstrap is tied to Bootstrap 3.3.7.1, an older version of Bootstrap. For Bootstrap 4, 5, or later, use `Bootstrap-Flask` instead.
fix
For modern Bootstrap versions, migrate to `Bootstrap-Flask`. Note that `Flask-Bootstrap` and `Bootstrap-Flask` cannot be used in the same Python environment.
affects: <=3.3.7.1
deprecatedThe project appears to be abandoned, with its last release in 2017 and PyPI classifiers indicating Python 2 support. There is no active development for newer Python or Bootstrap versions.
fix
For new projects or modern Bootstrap/Python versions, consider `Bootstrap-Flask`.
affects: All versions
gotchaWhen overriding template blocks (e.g., `styles`, `scripts`) in `bootstrap/base.html`, you must include `{{ super() }}` to retain Bootstrap's default content. Otherwise, your custom content will entirely overwrite Bootstrap's.
fix
Always use `{{ super() }}` within overridden blocks: `{% block styles %}{{ super() }} <link rel="stylesheet" href="/my_styles.css">{% endblock %}`
affects: All versions
gotchaThe correct way to initialize the extension is `bootstrap = Bootstrap(app)`. Simply calling `Bootstrap(app)` might work in some basic scenarios but the explicit assignment is recommended for consistency and proper behavior with certain Flask features.
fix
Ensure you assign the initialized extension to a variable: `bootstrap = Bootstrap(app)`.
affects: All versions
gotchaFlask-Bootstrap bundles jQuery 1.x. If your application or other JavaScript libraries require jQuery 2.x or later, you'll need to manually include the desired jQuery version via a CDN or local static files.
fix
Add a `script` tag for a newer jQuery version in your `{% block scripts %}` with `{{ super() }}`.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'flask_bootstrap'
The 'flask-bootstrap' library is not installed in the active Python environment.
fix
Run 'pip install flask-bootstrap' to install the library.
jinja2.exceptions.TemplateNotFound: bootstrap/base.html
Jinja2 cannot locate the 'bootstrap/base.html' template. This often happens if Flask-Bootstrap is not properly initialized, if there's a conflict with the newer Bootstrap-Flask library, or if the templates directory is incorrectly configured.
fix
Ensure you have 'from flask_bootstrap import Bootstrap' and 'Bootstrap(app)' in your application's setup. If you have both 'flask-bootstrap' and 'Bootstrap-Flask' installed, uninstall both and reinstall only the one you intend to use (e.g., 'pip uninstall flask-bootstrap bootstrap-flask' then 'pip install flask-bootstrap').
jinja2.exceptions.UndefinedError: 'bootstrap_find_resource' is undefined
The 'bootstrap_find_resource' Jinja2 filter is not recognized, typically because the Flask-Bootstrap extension was not correctly initialized with your Flask application or its blueprint was not registered.
fix
Verify that you have imported Bootstrap correctly with 'from flask_bootstrap import Bootstrap' and initialized it by passing your Flask app instance: 'bootstrap = Bootstrap(app)'.
ImportError: cannot import name 'Bootstrap5' from 'flask_bootstrap'
You are attempting to import 'Bootstrap5' from 'flask_bootstrap', but 'flask-bootstrap' (version 3.3.7.1) only supports Bootstrap 3. 'Bootstrap5' is a feature of the separate and newer 'Bootstrap-Flask' library, which uses the 'flask_bootstrap' package name for compatibility.
fix
If you intend to use Bootstrap 5, uninstall 'flask-bootstrap' and install 'Bootstrap-Flask' instead (e.g., 'pip uninstall flask-bootstrap && pip install Bootstrap-Flask'). The import statement 'from flask_bootstrap import Bootstrap5' will then correctly refer to the class provided by 'Bootstrap-Flask'.
Upgrade
Version history
3.3.7.1latest on PyPI · released Jan 11, 2017
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources