Flask extension to handle favicons.
Project description
Flask-favicon
Flask-favicon is a Flask extension which generates multiple favicon variants for different platforms. The goal is to cover as many devices as possible from a single image file. Flask-favicon serves all the assets for you and provides an easy to use Jinga template which you can include in your html <head>
.
Full Documentation: https://maxdup.github.io/flask-favicon/
Installation
Flask-favicon is available on the Python Package Index. This makes installing it with pip as easy as:
pip install flask-favicon
Initializing
The extension needs to be loaded alongside your Flask application. All favicons need to be declared during app creation with register_favicon()
. You may register any amount of favicons. You should have at least one favicon named as 'default'
Here's a minimal example of how this is done:
from flask import Flask, Blueprint
from flask_favicon import FlaskFavicon
flaskFavicon = FlaskFavicon()
app = Flask('my-app')
bp = Blueprint('my-blueprint', __name__)
app.register_blueprint(bp)
flaskFavicon.init_app(app)
flaskFavicon.register_favicon('source/favicon.png', 'default') # filename, favicon identifier
flaskFavicon.register_favicon('source/favicon-alt.png', 'default-alt')
flaskFavicon.register_favicon('source/promo.png', 'promo')
app.run()
Usage
Initiallizing FlaskFavicon
provides you with a Jinga template to be inserted in your <head>
.
<!-- _head.html -->
<head>
...
{% include "flask-favicon.html" %}
...
</head>
By default, the flask-favicon.html
template will be populated with the favicon registered as 'default'
.
To use the alternative favicons as declared earlier, you can use Flask-favicon's use_favicon
decorator alongside route declarations.
from flask import Blueprint, render_template
from flask_favicon import use_favicon
bp_site = Blueprint('site', __name__)
@bp_site.route("/")
# will use 'default' favicon
def index():
return render_template('index.html')
@bp_site.route("/promo")
@use_favicon('promo')
def promo():
return render_template('promo-page.html')
@bp_site.route("/special-event")
@use_favicon('default-alt')
def special_event():
return render_template('special-page.html')
NOTE:
@use_favicon()
comes after the@bp.route()
decorator.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file flask-favicon-0.1.3.tar.gz
.
File metadata
- Download URL: flask-favicon-0.1.3.tar.gz
- Upload date:
- Size: 17.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b65ca9f8cb1c0d7e4644a78e96b5a312e61591b429875fec524205a3ea44b51a |
|
MD5 | 7235440d41dafd704bc93605c5a9b92f |
|
BLAKE2b-256 | f5ac13303362266f7688980a9d34665459f7c1b016e1572d1fb22ffa6a7738d3 |
File details
Details for the file flask_favicon-0.1.3-py3-none-any.whl
.
File metadata
- Download URL: flask_favicon-0.1.3-py3-none-any.whl
- Upload date:
- Size: 18.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 92265326ecf7045fb8179291aefea5060830831b56c6570a0c670e61be783c5d |
|
MD5 | 5ab98941b9526a489d474735bbd930fc |
|
BLAKE2b-256 | 5648daf5cb7be33b83578afa35af8e9fcbf7c05e56ba581f3b729e5cad310392 |