Flask-Bootstrap

3.3.7.1 · abandoned · verified Tue Apr 14

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.

Warnings

Install

Imports

Quickstart

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)

view raw JSON →