【发布时间】:2016-07-27 11:16:59
【问题描述】:
我想导出以 ASCII 编码的 CSV 文件,但默认为 UTF-8 如果我对字符串进行编码,我会得到写在 csv (b'String') 中的字节码
response = HttpResponse(content_type='text/csv')
response['Content-Disposition'] = 'attachment; filename="datev_export.csv"'
writer = csv.writer(response, delimiter=";",)
row = ['some', 'strings']
writer.writerow(first_row)
return response
那么如何在没有前导 b'' 的情况下将我的字符串编码为 ASCII?
【问题讨论】:
-
您的代码不会对我在 Python 3 上使用 Django 1.9 产生问题。CSV 文件不包含
b""前缀,默认编码为 ascii。贴出产生问题的代码和相关数据。
标签: python django export-to-csv