所以我的 CSV 文件用引号保存,如下所示:
“名字”、“姓氏”、“电子邮件”、“状态”、“类型”、“公司名称”
“Bugs”、“Bunny”、“bbb@bugsbb.com”、“活跃”、“IT”、“胡萝卜”
有没有办法删除那些引号?
这是我的代码:
response = HttpResponse(content_type='text/csv')
response['Content-Disposition'] = 'attachment; filename="file.csv"'
members = Member.objects.all().filter(......)
csv_data = [(str('First name'), str('Last name'), str('Email'), str('Status'), str('Type'), str('Company name'))]
for member in members:
current_company = member.current_company.name if member.current_company else None
csv_data.append(
[
str(member.first_name),
str(member.last_name),
str(member.email),
str(member.member_Status),
str(member.member_type),
str(current_company)
])
t = loader.get_template('export_members.txt')
c = Context({'data': csv_data})
response.write(t.render(c))
return response
我还尝试将整个 csv_data 转换为二进制...但它没有用。