Python:Flask-Static-Digest 用于處理靜態文件緩存問題
Flask-static-Digest 用于處理靜態文件
文檔:https://github.com/nickjj/flask-static-digest
安裝
pip install Flask-Static-Digest
1
使用示例
# -*- coding: utf-8 -*- from flask import Flask, render_template from flask_static_digest import FlaskStaticDigest app = Flask(__name__) # 注冊 FlaskStaticDigest(app) # 路由 @app.route('/') def hello_world(): return render_template('index.html') if __name__ == '__main__': app.run(debug=True)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
index.html
1
2
3
4
配置環境變量 .env
FLASK_APP=hello.app FLASK_ENV=development
1
2
命令行執行
$ flask digest compile
1
啟動服務
http://127.0.0.1:5500/
渲染結果
1
2
3
4
5
配置參數
FLASK_STATIC_DIGEST_BLACKLIST_FILTER = [] # If you want specific extensions to not get md5 tagged you can add them to # the list, such as: [".htm", ".html", ".txt"]. Make sure to include the ".". FLASK_STATIC_DIGEST_GZIP_FILES = True # When set to False then gzipped files will not be created but static files # will still get md5 tagged. FLASK_STATIC_DIGEST_HOST_URL = None # When set to a value such as https://cdn.example.com and you use static_url_for # it will prefix your static path with this URL. This would be useful if you # host your files from a CDN. Make sure to include the protocol (aka. https://).
1
2
3
4
5
6
7
8
9
10
11
12
Flask Python
版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。
版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。