Flask-Hmin
安装
使用pip进行安装:
pip install Flask-Hmin
或者使用pipenv:
pipenv install Flask-Hmin
或者使用poetry:
poetry add Flask-Hmin
您也可以下载存储库并手动安装它,执行以下操作:
git clone https://github.com/zhenzi0322/Flask-Hmin.git
cd Flask-Hmin
python setup.py install
使用方法
所有模板视图html都压缩
from flask import Flask, render_template
from flask_hmin import HMin
app = Flask(__name__)
app.config["HMIN_COMPRESS_HTML"] = True
HMin(app=app)
@app.route("/")
def home():
return render_template("index.html")
if __name__ == '__main__':
app.run()
指定某个模板视图不压缩
from flask import Flask, render_template
from flask_hmin import HMin
app = Flask(__name__)
app.config["HMIN_COMPRESS_HTML"] = True
hmin = HMin(app=app)
@app.route("/")
@hmin.not_compress
def home():
# 该视图模板不压缩
return render_template("index.html")
@app.route("/test")
def test():
return render_template("index.html")
if __name__ == '__main__':
app.run()
把模板HTML内容加载到Redis中
from flask import Flask, render_template
from flask_hmin import HMin
app = Flask(__name__)
app.config["HMIN_COMPRESS_HTML"] = True
app.config['HTML_LOAD_REDIS'] = True
hmin = HMin(app=app, redis_config={'host': "localhost", "port": 6379, "db": 0, "password": ''})
@app.route("/")
def home():
return render_template("index.html")
if __name__ == '__main__':
app.run()
默认过期时间是一天。86400秒。
如果需要自定义Redis过期时间,如下:
app.config['EXPIRIES_TIME'] = 300
上面是配置300秒过期。
Metadata
Release files for Flask-Hmin 1.0.2
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-Hmin-1.0.2.tar.gz | 4.0 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| Flask_Hmin-1.0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.5 kB
Release files / Flask-Hmin-1.0.2.tar.gz
| Download URL | Flask-Hmin-1.0.2.tar.gz |
|---|---|
| Size | 4.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b079653a905bac7d35d29c36970247c3b4496e69eef701000de73f19dc8bcded
|
|
BLAKE2b-256 checksum How to use checksums |
a4c1c804e23051796f931452a1e0a22a79c5fe582fa984e755b8f5c3b80edb59
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.7.5
|
Release files / Flask_Hmin-1.0.2-py3-none-any.whl
| Download URL | Flask_Hmin-1.0.2-py3-none-any.whl |
|---|---|
| Size | 4.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a15e551d7633576afad535eade0b97fc4631981fd2edb0ea1913573dc4a5b8f0
|
|
BLAKE2b-256 checksum How to use checksums |
7451446584ff071432c28f9e251ec037c85dd5d66f7f6ff8ae534064736fe6bb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.7.5
|
Security for Flask-Hmin 1.0.2
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.