小编Dan*_*ock的帖子

Python Flask send_file StringIO空白文件

我正在使用python 3.5和flask 0.10.1并且喜欢它,但是在send_file上遇到了一些麻烦.我最终想要处理一个pandas数据帧(来自Form数据,在本例中未使用但将来是必需的)并将其作为csv(没有临时文件)发送到下载.我见过的最好的方法是给我们StringIO.

这是我试图使用的代码:

@app.route('/test_download', methods = ['POST'])
def test_download():
    buffer = StringIO()
    buffer.write('Just some letters.')
    buffer.seek(0)
    return send_file(buffer, as_attachment = True,\
    attachment_filename = 'a_file.txt', mimetype = 'text/csv')
Run Code Online (Sandbox Code Playgroud)

使用正确的名称下载文件,但文件完全空白.

有任何想法吗?编码问题?有没有在其他地方回答过?谢谢!

python stringio flask

19
推荐指数
2
解决办法
1万
查看次数

标签 统计

flask ×1

python ×1

stringio ×1