我想在我的目录下写下一个文本文件,以便在Flask中使用make\ u response,但是我写下的代码不起作用
下面是我写的一段代码,用make\ u response下载一个文本文件
@api.route('/structure_voice_log', methods=['POST'])
def download():
response = make_response("hogehoge")
response.headers["Content-Disposition"] = "attachment; filename=outbound.txt"
response.headers["Content-type"] = "text/plain"
return response
这是我发出的命令
curl -L -i -H "Content-Type: application/json" http://localhost:17354/structure_voice_log -X POST -d '{"voice_log": "hogehoge"}'
以下是上述命令结束后的结果
HTTP/1.0 200 OK
Content-type: text/plain
Content-Length: 8
Content-Disposition: attachment; filename=outbound.txt
Access-Control-Allow-Origin: *
Server: Werkzeug/0.15.5 Python/3.7.5
Date: Tue, 12 Nov 2019 16:15:44 GMT
hogehoge%
我得到的只是一个字符串“hogehoge”,而不是一个文本文件。 我怎样才能做到? 使用这个框架可能会出错。 如果你能帮我,我会非常感激的
make_response
接受要显示的字符串的第一个参数。 可以改用send_file
函数(https://pythonise.com/series/learning-flask/sending-files-with-flask)希望有帮助。 致以最诚挚的问候
相关问题 更多 >
编程相关推荐