Django下载文件在Internet Explorer 11中不起作用

时间:2015-03-06 14:35:12

标签: django internet-explorer downloadfile

我正在编写一个Django应用程序,它上传文件,对其进行签名并将签名文件返回给浏览器,以便用户可以将文件“另存为”到磁盘。我的代码在firefox和chrome中运行,但在Internet Explorer 11中挂起。 我的上传功能如下:

from django.http import HttpResponseRedirect, HttpResponse
from django.template import RequestContext, loader

def upload_file(request) : # request to display the upload file page
   if request.method != 'POST' :
      t = loader.get_template("upload.html")
      c = RequestContext(request)
      return HttpResponse(t.render(c))
   else :  # Upload and sign file
      files = request.FILES.getlist('upfiles')  # sign, save etc.
      retstr = "A temporary file to be saved by the browser."
      response = HttpResponse(retstr, mimetype='application/octet-stream')
      response['Content-Disposition'] = 'attachment; filename=notice.txt'
      response['content-length'] = str(len(retstr))
      return response

使用IE 11时,下载会在标题选项卡中以圆圈图标挂起。

但是,如果我把代码拿出来并放入一个单独的函数中:

def download_test(request) :
   retstr = "A temporary file to be saved by the browser."
   response = HttpResponse(retstr, mimetype='application/octet-stream')
   response['Content-Disposition'] = 'attachment; filename=notice.txt'
   response['content-length'] = str(len(retstr))
   return response

这也适用于Internet Explorer 11。怎么了 ? IE不允许在POST请求中下载文件?任何帮助将不胜感激。

0 个答案:

没有答案