• Stars
    star
    1,109
  • Rank 41,591 (Top 0.9 %)
  • Language SCSS
  • License
    Other
  • Created over 6 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Bootstrap 4 & 5 helper for your Flask projects.

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

Live demos of the latest release are:

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.

More Repositories

1

flask-tutorial

Flask ε…₯门教程 / Flask for Beginners
HTML
804
star
2

watchlist

Example application for Flask tutorial "Flask ε…₯门教程".
Python
260
star
3

flask-dropzone

Upload files in Flask application with Dropzone.js.
Python
250
star
4

flask-ckeditor

CKEditor integration for Flask, including image upload, code syntax highlight, and more.
JavaScript
199
star
5

flask-examples

Example applications for Flask learners.
JavaScript
185
star
6

flask-origin

Flask 0.1η‰ˆζœ¬ζΊη ζ³¨θ§£γ€‚
Python
179
star
7

flask-jobs

Flask-related job opportunities.
74
star
8

todo

This project is deprecated in favour of Todoism.
HTML
66
star
9

timer

A simple countdown timer made with Flask and JavaScript.
CSS
55
star
10

calculator

A Calculator made by Flask and JavaScript.
HTML
48
star
11

flask-avatars

All avatar generators in one place.
JavaScript
28
star
12

flask-upload-dropzone

Flask File Upload with Dropzone.js.
JavaScript
28
star
13

cloud-drive

A minimal photo upload and manage system with Flask and Flask-Uploads (Multiple file upload support!).
Python
26
star
14

flask-share

Create social share component in Jinja2 template based on share.js.
Python
20
star
15

guess

A Flask version of "Guess the Number" game.
HTML
20
star
16

flemi-api

Flemi API
Python
10
star
17

github-login

Example application for login with GitHub by GitHub-Flask
Python
8
star
18

flask-structure

Different application structure for Flask.
Python
3
star
19

flemi-front

The frontend part of the Flemi project
TypeScript
1
star
20

flask-sse-demo

Example application for Server-Sent Event by Flask-SSE
HTML
1
star