Skip to main content

Flask extension to handle favicons.

Project description

License: GPL v3 PyPI pyversions Platforms PyPI version fury.io GitHub Workflow Status (with event) Coverage

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

flask-favicon-0.1.4.tar.gz (22.1 kB view details)

Uploaded Source

Built Distribution

flask_favicon-0.1.4-py3-none-any.whl (24.1 kB view details)

Uploaded Python 3

File details

Details for the file flask-favicon-0.1.4.tar.gz.

File metadata

  • Download URL: flask-favicon-0.1.4.tar.gz
  • Upload date:
  • Size: 22.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for flask-favicon-0.1.4.tar.gz
Algorithm Hash digest
SHA256 8ad7110fc5b9f885fc368334a56de9b8b1f757897aed3b07439a0d28a798d202
MD5 dd7d21877587f5d097e0dee1a599ac45
BLAKE2b-256 153426b316b187b9dc1179a10e4292b16b351a4d38c91f6e7310c8a48e1bc9f2

See more details on using hashes here.

File details

Details for the file flask_favicon-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for flask_favicon-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 9feb82917299f46aef840a9bb1ce7acb904786c65d2b3bff68e012c8e9442504
MD5 9e5797223c9054d3c734837581c71c8e
BLAKE2b-256 ab85c9670642c562a125ae4b91b0640fa25911ca04daf68039d1f06a54973577

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page