Flask-Cache-Manifest
Flask-cache-manifest is a Flask extension to help you serve your md5 hashed assets. Having file hashes in filenames is a popular feature of modern asset bundlers. It's a good strategy for browser cache busting. However, Flask does not provide an easy way to reference those complicated and ever-changing filenames. Flask-cache-manifest lets you reference those assets by leveraging cache_manifest.json files.
Full Documentation: https://maxdup.github.io/flask-cache-manifest/
Turns:
<link type="text/css" rel="stylesheet"
href="{{ hashed_url_for('static', filename='css/app.css') }}">
into:
<link type="text/css" rel="stylesheet"
href="/static/css/app-d41d8cd98f00b204e9800998ecf8427e.css">
Installation
pip install flask-cache-manifest
Initializing
The extension needs to be loaded alongside your Flask application.
Here's how it's done:
from flask import Flask, Blueprint
from flask_cache_manifest import FlaskCacheManifest
flaskCacheManifest = FlaskCacheManifest()
app = Flask('my-app',
static_folder='dist/static',
static_url_path='/static')
bp = Blueprint('my-blueprint',
__name__,
static_folder='blueprints/static',
static_url_path='/bp/static')
app.register_blueprint(bp)
flaskCacheManifest.init_app(app)
app.run()
NOTE:
Ideally, flaskCacheManifest.init_app needs to be called after you've registered your blueprints.
Static folders registered after init_app will not be loaded.
Usage
Flask-cache-manifest adds the hashed_url_for function for use in your templates.
It is analogous to Flask's url_for. Given the above example and its blueprints,
here's how you would be able to reference your static files in your Jinja templates.
<!-- from the app's static folder -->
<link type="text/css" rel="stylesheet"
href="{{ hashed_url_for('static', filename='css/app.css') }}">
<!-- from the blueprint's static folder -->
<link type="text/css" rel="stylesheet"
href="{{ hashed_url_for('my-blueprint.static', filename='css/app.css') }}">
<!-- from the static folder relative to what is currently being rendered -->
<link type="text/css" rel="stylesheet"
href="{{ hashed_url_for('.static', filename='css/app.css') }}">
Metadata
Release files for flask-cache-manifest 1.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| flask-cache-manifest-1.0.4.tar.gz | 5.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| flask_cache_manifest-1.0.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.8 kB
Release files / flask-cache-manifest-1.0.4.tar.gz
| Download URL | flask-cache-manifest-1.0.4.tar.gz |
|---|---|
| Size | 5.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
40db6de5273a87a576c7a3d4efe70fb7d196eb45619d4b4dab8edcaeeaa30bb7
|
|
BLAKE2b-256 checksum How to use checksums |
78c2250e9e7deab8c3a71c19ead8ef5358b6a7a9b2d879a01daeb18914fe020f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.4
|
Release files / flask_cache_manifest-1.0.4-py3-none-any.whl
| Download URL | flask_cache_manifest-1.0.4-py3-none-any.whl |
|---|---|
| Size | 5.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3342d2fa3f0c91c6d1e915e6687245afac1a739e1322aa633d16cfcda5adf2fc
|
|
BLAKE2b-256 checksum How to use checksums |
de29ca043728febe8504885fa7f9b3bd4a1a7d9036b2b309993a5958ca3a2f47
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.4
|
Security for flask-cache-manifest 1.0.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.