在Flask想要实现文件下载功能,只需要导入

send_from_directory(directory, filename, **options)

然后在视图函数中返回该函数即可

示例代码如下

from flask import Flask, send_from_directory

app = Flask(__name__)

@app.route("/download")
def index():
    return send_from_directory(r"D:\desk\id",filename="123.jpg",as_attachment=True)

if __name__ == '__main__':
    print(app.url_map)
    app.run(host="10.205.1.15", port=5000)

访问 http://10.205.1.15/download 即可下载123.jpg文件

相关文章:

  • 2021-12-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-09
  • 2021-06-22
猜你喜欢
  • 2022-12-23
  • 2021-10-10
  • 2021-08-22
  • 2022-01-20
  • 2021-12-06
  • 2021-08-16
相关资源
相似解决方案