from rexec import FileWrapper#安装这个包
wrapper = FileWrapper(open(pull_path, "rb"))#pull_path是文件绝对路径
response = HttpResponse(wrapper, mimetype='application/%s' % strSuffix)#strSuffix下载文件名
response['Content-Type'] = "application/%s;charset=utf-8" % strSuffix
try:
strFileName=strFileName.encode('gb2312') #IE下乱码,转换中文编码
content_disposition = 'attachment;filename="%s"' % strFileName
response['Content-Disposition'] = content_disposition
except Exception, e:
response['Content-Disposition'] = 'attachment; filename=%s' % strFileName
return response