python后端向前台返回字节流文件

python后端向前台返回字节流文件,浏览器访问地址自动下载文件:

# 要下载的文件路径
the_file_name = "record.txt"
# 这里创建返回
 response = StreamingHttpResponse(self.file_iterator(the_file_name))
# 注意格式
 response['Content-Type'] = 'application/txt'
# 注意filename 这个是下载后的名字
response['Content-Disposition'] = 'attachment;filename="record.txt"'
return response

  

猜你喜欢

转载自www.cnblogs.com/zhangshengxiang/p/10873681.html
今日推荐