Using tempfile to create pdf/xls documents in flask

﹥>﹥吖頭↗ 提交于 2019-12-01 12:17:12

Use tempfile.mkstemp() which will create a standard temp file on disk which will persist until removed:

import tempfile
import os

handle, filepath = tempfile.mkstemp()
f = os.fdopen(handle)  # convert raw handle to file object
...

EDIT tempfile.TemporaryFile() will be destroyed as soon as it's closed, which is why your code above is failing.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!