Skip to content

Instantly share code, notes, and snippets.

@nitinbhojwani
Created April 30, 2016 08:27
Show Gist options
  • Save nitinbhojwani/a1865fd8af0935e47e73d4f1ba3e563c to your computer and use it in GitHub Desktop.
Save nitinbhojwani/a1865fd8af0935e47e73d4f1ba3e563c to your computer and use it in GitHub Desktop.
Django - Send CSV File as Attachment in Response
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