Flask压缩Html
Project description
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秒过期。
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Flask-Hmin-1.0.2.tar.gz
(4.0 kB
view hashes)
Built Distribution
Close
Hashes for Flask_Hmin-1.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a15e551d7633576afad535eade0b97fc4631981fd2edb0ea1913573dc4a5b8f0 |
|
MD5 | 79f39890fd2c1a9b54fe48ea7068512a |
|
BLAKE2b-256 | 7451446584ff071432c28f9e251ec037c85dd5d66f7f6ff8ae534064736fe6bb |