
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Defines a SQLALchemy Mixin for creating Bootstrap download buttons in a Flask application.
Flask-Download-Btn defines a SQLALchemy Mixin for creating Bootstrap download buttons in a Flask application.
Its features include:
$ pip install flask-download-btn
Our folder structure will look like:
templates/
index.html
app.py
In templates/index.html
, paste the following Jinja template:
<html>
<head>
<!-- include Bootstrap CSS and Javascript -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
<!-- include download button script -->
{{ download_btn.script() }}
</head>
<body>
<!-- render the download button and progress bar -->
{{ download_btn.btn.render() }}
{{ download_btn.render_progress() }}
</body>
</html>
In app.py
:
from flask_download_btn import DownloadBtnManager, DownloadBtnMixin
from flask import Flask, render_template, session
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy.ext.orderinglist import ordering_list
app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app)
# initialize download button manager with application and database
download_btn_manager = DownloadBtnManager(app, db=db)
# create download button model and register it with the manager
@DownloadBtnManager.register
class DownloadBtn(DownloadBtnMixin, db.Model):
id = db.Column(db.Integer, primary_key=True)
# create the database and clear the session when the app starts
@app.before_first_request
def before_first_request():
db.create_all()
session.clear()
HELLO_WORLD_URL = 'https://test-bucket2357.s3.us-east-2.amazonaws.com/hello_world.txt'
# basic use
@app.route('/')
def index():
btn = DownloadBtn()
btn.downloads = [(HELLO_WORLD_URL, 'hello_world.txt')]
db.session.commit()
return render_template('index.html', download_btn=btn)
Run the app with:
$ python app.py
And navigate to http://localhost:5000/. Click the download button to download a text file with 'Hello, World!'
.
@software{bowen2020flask-download-btn,
author = {Dillon Bowen},
title = {Flask-Download-Btn},
url = {https://dsbowen.github.io/flask-download-btn/},
date = {2020-06-17},
}
Users must cite this package in any publications which use it.
It is licensed with the MIT License.
FAQs
Defines a SQLALchemy Mixin for creating Bootstrap download buttons in a Flask application.
We found that flask-download-btn demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.