Skip to main content

Bootstrap-Flask

PyPI - License Current version on PyPI Build status Coverage Status Open Collective

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 Pagination object 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) }}):

form rendering

When the validation fails, the error messages will be rendered with proper style:

error form rendering

Read the Basic Usage docs for more details.

Live demo

https://bootstrap-flask-example.azurewebsites.net/

Donate

If you find Bootstrap-Flask useful, please consider donating today. Your donation keeps Bootstrap-Flask maintained and updated with Bootstrap.

Links

Notes for Bootstrap 4 & 5 support

The Bootstrap 5 support is added in Bootstrap-Flask 2.0 version. Now you can use the separate extension class for different Bootstrap major versions.

For Bootstrap 4, use the Bootstrap4 class:

from flask_bootstrap import Bootstrap4

# ...
bootstrap = Bootstrap4(app)

and import macros from the template path bootstrap4/:

{% from 'bootstrap4/form.html' import render_form %}

For Bootstrap 5, use the Bootstrap5 class:

from flask_bootstrap import Bootstrap5

# ...
bootstrap = Bootstrap5(app)

and import macros from the template path bootstrap5/:

{% from 'bootstrap5/form.html' import render_form %}

The Bootstrap class and bootstrap/ template path are deprecated since 2.0 and will be removed in 3.0.

Migration from Flask-Bootstrap

If you come from Flask-Bootstrap, check out this tutorial on how to migrate to this extension.

Contributing

For guidance on setting up a development environment and how to make a contribution to Bootstrap-Flask, see the development documentation and Flask's contributing guidelines.

License

This project is licensed under the MIT License (see the LICENSE file for details). Some macros were part of Flask-Bootstrap and were modified under the terms of its BSD License.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bootstrap_flask-2.6.0.tar.gz (4.6 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bootstrap_flask-2.6.0-py3-none-any.whl (4.7 MB view details)

Uploaded Python 3

File details

Details for the file bootstrap_flask-2.6.0.tar.gz.

File metadata

  • Download URL: bootstrap_flask-2.6.0.tar.gz
  • Upload date:
  • Size: 4.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for bootstrap_flask-2.6.0.tar.gz
Algorithm Hash digest
SHA256 2b0849f77a743e117716a75406b0312f0783658589519b0e922054bfb3102b9f
MD5 4edbf423c28c212f6cba1e0862a4a958
BLAKE2b-256 0086bea605321c923d9b65f33434c97adaf8e39b6a76e7af081ed638f2ecf072

See more details on using hashes here.

Provenance

The following attestation bundles were made for bootstrap_flask-2.6.0.tar.gz:

Publisher: release.yml on helloflask/bootstrap-flask

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bootstrap_flask-2.6.0-py3-none-any.whl.

File metadata

File hashes

Hashes for bootstrap_flask-2.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2a0ff1df295b143020743949419c955de23ffc3465518f4bf5bac32f90deaa52
MD5 b370c6c777fca491593e09c63ae5396e
BLAKE2b-256 1c12627718708a73fcc4ce713651aaad4dd91eb92e4e47b5abaea0848e4778cf

See more details on using hashes here.

Provenance

The following attestation bundles were made for bootstrap_flask-2.6.0-py3-none-any.whl:

Publisher: release.yml on helloflask/bootstrap-flask

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

2.6.0 This release

2 files

2.5.0

2 files

2.4.2

2 files

2.4.1

2 files

2.4.0

2 files

2.3.3

2 files

2.3.2

2 files

2.3.1

2 files

2.3.0

2 files

2.2.0

2 files

2.1.0

2 files

2.0.2

2 files

2.0.1

2 files

2.0.0

2 files

1.8.0

2 files

1.7.0

2 files

1.6.0

2 files

1.5.3

2 files

1.5.2

2 files

1.5.1

2 files

1.5

2 files

1.4

2 files

1.3.2

2 files

1.3.1

2 files

1.3.0

2 files

1.2.0

2 files

1.1.0

1 file

1.0.10

2 files

1.0.9

2 files

1.0.8

2 files

1.0.7

2 files

1.0.6

2 files

1.0.5

2 files

1.0.4

2 files

1.0.3

2 files

1.0.2

2 files

1.0.1

2 files

1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page