【发布时间】:2021-09-16 07:28:31
【问题描述】:
我无法通过烧瓶 send_file 下载 html 文件。
-
基本上,单独下载一个 html 文件,它工作得很好。通过将流作为参数提供给 send_file 函数
-
但是;我需要将此文件与其他不相关的文件一起放入一个 zip 文件中。在那里,在 write 函数中,流和字符串 (result_html) 都不起作用。我需要以某种方式将其直接转换为 html 文件并放入 zip 文件中
我暂时不知道该怎么做。我将数据(输出)作为字典...
谢谢指点
from flask import render_template, send_file
from io import BytesIO
result_html = render_template('myResult.html', **output)
result_stream = BytesIO(str(result_html).encode())
with ZipFile("zipped_result.zip", "w") as zf:
zf.write(result_html)
# zf.write(other_files)
send_file(zf, as_attachment=True, attachment_filename="myfile.zip")
【问题讨论】:
标签: python html flask zipfile sendfile