Created
April 30, 2016 08:27
-
-
Save nitinbhojwani/a1865fd8af0935e47e73d4f1ba3e563c to your computer and use it in GitHub Desktop.
Django - Send CSV File as Attachment in Response
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def dowload_view(request): | |
from django.http import HttpResponse | |
rows = [['name', 'city', 'email'], ['Nitin', 'Bengaluru', 'nitinbhojwani1993@gmail.com']] | |
response = HttpResponse(content_type='text/csv') | |
response['Content-Disposition'] = 'attachment; filename="download.csv"' | |
writer = csv.writer(response) | |
for row in rows: | |
writer.writerow(row) | |
return response |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment