python django - 在IE 8中没有下载csv文件

时间:2013-05-27 07:55:36

标签: python django

我正在使用Django下载这样的CSV文件:

    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")

适用于FF,Chrome,IE> = 9但不适用于IE< = 8

有谁知道区别是什么?

1 个答案:

答案 0 :(得分:0)

试试这个:

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

此外,如果文件名中包含空格,加号和减号,则urlencode非常有用。否则IE将无效。