0

I am using Django to download a CSV file like this:

    response['Content-Type'] = 'application/force-download'
    response['Cache-Control'] = 'public'
    response['Content-Disposition'] = 'attachment; filename="results.csv"'
    writer = UnicodeWriter(response, quoting=csv.QUOTE_ALL, encoding="utf-8")

It works in FF, Chrome, IE>=9 but not IE<=8

Does anyone know what the difference is?

Jacinda
  • 4,932
  • 3
  • 26
  • 37
user2424160
  • 257
  • 2
  • 4
  • 9
  • What if you try `application/octet-stream` instead of `application/force-download`? `application/force-download` is not a standard content-type and you'll have problems with browser support. – alecxe May 27 '13 at 07:59
  • This is a duplicate question: http://stackoverflow.com/questions/2232103/how-do-i-get-csv-file-to-download-on-ie-works-on-firefox – Jacinda May 27 '13 at 08:02
  • Also, this forum thread also talks about the issue: http://www.htmlforums.com/php-programming/t-force-download-in-ie8-is-it-impossible-117254.html – Jacinda May 27 '13 at 08:03
  • i already tried all that – user2424160 May 27 '13 at 08:12
  • @user2424160 Please include all the attempts you made. It would be sad if more suggestions come in you've already tried. Also please **edit** your question to include all these details. Comments aren't really fit for this on a Q&A site. – gertvdijk May 27 '13 at 09:29

1 Answers1

0

Try this:

csv_name = urllib.urlencode({'filename':'"results.csv"'})  #this is if you really really want the double quotes, otherwise just use cvs_name = 'results.csv'

response = HttpResponse(csv_content, mimetype='text/csv')
response['Content-Disposition'] = 'attachment; ' + csv_name + '.csv'
response['Content-Type']        = 'text/csv; charset=utf-8';

return response

Also, the urlencode is useful in case you have spaces, pluses, minuses in the file name. Otherwise IE will not work.

Ciprian Tarta
  • 484
  • 5
  • 12