django 导出csv
django csv导出
def test_csv_download(request):
import csv
response = HttpResponse(content_type='text/csv')
list_table=['s','d','e','f','g','h']
response=HttpResponse(content_type='text/csv')
response['Content-Disposition'] = 'attachment; filename="somefilename.csv"'
#或者写成
# response=HttpResponse(content_type='text/csv',headers={'Content-Disposition': 'attachment; filename="somefilename.csv"'})
write=csv.writer(response)
for i in list_table:
write.writerow(i)
return response