flask打包下载zip文件

flask打包下载zip文件

@app.route('/download_all')
def download_all():
    zipf = zipfile.ZipFile('Name.zip','w', zipfile.ZIP_DEFLATED)
    root_path = app.root_path + app.config['UPLOAD']['prefix_path']
    app.logger.info(root_path)
    for root,dirs, files in os.walk(root_path):
        for file in files:
            os.chdir(root)  # 定位到文件夹
            zipf.write(file)
    zipf.close()
    return send_file('Name.zip',
            mimetype = 'zip',
            attachment_filename= 'Name.zip',
            as_attachment = True)
原文地址:https://www.cnblogs.com/xiao-apple36/p/12500782.html