0

我正在使用 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

有谁知道有什么区别?

4

1 回答 1

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 将无法工作。

于 2013-05-27T14:25:14.043 回答