Monday, September 25, 2017

Weird issue in outputting CSV files for downloading in django


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

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/09e4a016-429c-4669-9846-ade530a139e7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment