环境为 django 环境
- 因需求需要下载 CSV 文件并且不存储生成文件,所以想到了内存存储
from io import StringIO
StringIO
在内存中读写 str 字符串注意
是 str- 操作示例
import csv from io import StringIO customer_list = ['姓名'] f = StringIO() data = csv.writer(f) data.writerow(customer_list) response = StreamingHttpResponse(f.getvalue()) response['Content_Type'] = 'text/csv' response['Content-Disposition'] = 'attachment; filename="{0}"'.format('xx列表.xls') return response
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于