Skip to content

Instantly share code, notes, and snippets.

@jayapal
Created October 18, 2014 09:10
Show Gist options
  • Save jayapal/a164a06a671141b6d8dc to your computer and use it in GitHub Desktop.
Save jayapal/a164a06a671141b6d8dc to your computer and use it in GitHub Desktop.
response = HttpResponse(content_type='text/csv')
response['Content-Disposition'] = 'attachment; filename="data.csv"'
writer = csv.writer(response)
result = [{"user": 'jai', "email": "jai@gmail.com"}, {"user": 'jai', "email": "jai@gmail.com"}.............]
if result:
header= result[0].keys()
writer.writerow(header)
for row in result:
data = []
for key in header:
data.append(row[key])
writer.writerow(data)
return response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment