下载的东西是这样,不管是什么文件名字都是这,这是什么鬼??
改善后下载的中文档案 会显示名字:
改善后代码:
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