Weird issue in outputting CSV files for downloading in django

16 views
Skip to first unread message

BIJAL MANIAR

unread,
Sep 25, 2017, 5:32:39 AM9/25/17
to Django users

Hi,
I want my view to respond with a file for downloading, so that the browser pops up the download/file save dialog.
I am using the 'Content-Disposition' header to specify the name of the file.
When I use the django development server, it works perfectly fine in all browsers
When I run it on production with apache mod_wsgi python3.5, on chrome it gives Failed - Network error. It doesn't work on firefox and IE as well.
Any help would be appreciated.

def download_function():
filename = '/test/A.sv'
download_name = "example.csv"
with open(filename, 'r') as myfile:
response = HttpResponse(myfile, content_type='text/csv')
response['Content-Disposition'] = 'attachment; filename=%s' % download_name
response['Content-Length'] = os.path.getsize(filename)
return response

Thanks,
Bijal

Reply all
Reply to author
Forward
0 new messages