code
from flask import Flask, send_from_directory import os cur_dir=os.path.dirname(__file__) app = Flask(__name__) @app.route("/download") def index(): return send_from_directory(cur_dir,filename="test.png",as_attachment=True) if __name__ == '__main__': print(app.url_map) app.run(host="0.0.0.0", port=9900)
访问本地
http://127.0.0.1:9900/download
即可下载测试的图片。