django 實現下載中文名檔案 不顯示問題解決(下載檔名字只顯示 下載 解決)
阿新 • • 發佈:2018-12-01
下載的東西是這樣,不管是什麼檔名字都是這,這是什麼鬼??
改善後下載的中文件案 會顯示名字:
改善後程式碼:
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