1. 程式人生 > >Django下載檔案時,中文檔名問題

Django下載檔案時,中文檔名問題

原始碼:
response['Content_Type']='application/octet-stream'
response["Content-Disposition"] = "attachment; filename=%s" % name

下載的檔名為name,名字中有中文,下載時提示一下錯誤:


解決辦法:

response['Content_Type']='application/octet-stream'response["Content-Disposition"] = "attachment; filename={0}".format(name.encode('utf8'))
參考網址: