django 实现下载中文名文件 不显示问题解决(下载文件名字只显示 下载 解决)

下载的东西是这样,不管是什么文件名字都是这,这是什么鬼??

改善后下载的中文档案 会显示名字:

改善后代码:

from django.utils.http import urlquote
file_name_chinese = obj.files.first().name
response['Content-Disposition'] = 'attachment;filename="%s"'%(urlquote(file_name_chinese))
            outfile = open(filename, "rb")
            response = FileResponse(outfile)
            response['Content-Type'] = 'application/octet-stream'
            from django.utils.http import urlquote
            file_name_chinese = obj.files.first().name
            response['Content-Disposition'] = 'attachment;filename="%s"'%(urlquote(file_name_chinese))
            print(obj.files.first().name)
            return response

原代码:

  outfile = open(filename, "rb")
            response = FileResponse(outfile)
            response['Content-Type'] = 'application/octet-stream'
            response['Content-Disposition'] = 'attachment;filename="%s"' % obj.files.first().name
            return response

猜你喜欢

转载自blog.csdn.net/java_raylu/article/details/84556650