Bootstrap 4 & 5 helper for your Flask projects.
Maintained. Last release 3 months ago, commits in 3 of the last 26 weeks. Weaker on commit activity and release cadence.
pip install bootstrap-flaskBootstrap-Flask
Bootstrap-Flask is a collection of Jinja macros for Bootstrap 4 & 5 and Flask. It helps you to render Flask-related data and objects to Bootstrap markup HTML more easily:
- Render Flask-WTF/WTForms form object to Bootstrap Form.
- Render data objects (dict or class objects) to Bootstrap Table.
- Render Flask-SQLAlchemy
Paginationobject to Bootstrap Pagination. - etc.
Installation
$ pip install -U bootstrap-flask
Example
Register the extension:
from flask import Flask
# To follow the naming rule of Flask extension, although
# this project's name is Bootstrap-Flask, the actual package
# installed is named `flask_bootstrap`.
from flask_bootstrap import Bootstrap5
app = Flask(__name__)
bootstrap = Bootstrap5(app)
Assuming you have a Flask-WTF form like this:
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()
Now with the render_form macro:
{% from 'bootstrap5/form.html' import render_form %}
<html>
<head>
<!-- Bootstrap CSS -->
</head>
<body>
<h2>Login</h2>
{{ render_form(form) }}
<!-- Bootstrap JS -->
</body>
</html>
You will get a form like this with only one line code (i.e. {{ render_form(form) }}):

