当前位置:网站首页>flask返回文件下载

flask返回文件下载

2022-07-06 07:48:00 nongcunqq

from flask import Flask, send_from_directory
import os
app = Flask(__name__)

@app.route("/download")
def index():
    print(os.getcwd())
    filename = "1.png"
    path = os.path.join(os.getcwd(), filename)
    return send_from_directory(path=path, directory=os.getcwd(),  filename=filename,as_attachment=True)
    # return send_from_directory(path='./upload/upload_cnews.xlsx', directory='./upload', filename='upload_cnews.xlsx',
    # as_attachment=True)

参考
https://blog.csdn.net/qq_37754830/article/details/118884561

原网站

版权声明
本文为[nongcunqq]所创,转载请带上原文链接,感谢
https://blog.csdn.net/nongcunqq/article/details/125617810