私信  •  关注

calm

calm 最近创建的主题
calm 最近回复了
10 年前
回复了 calm 创建的主题 » 请问djang怎么下载文件啊

编辑器编辑出来的有点乱。。。如果看不清楚或有问题就qq我,1041315735@qq.com

10 年前
回复了 calm 创建的主题 » 请问djang怎么下载文件啊

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