[TimLinux] django 下载功能中文文件名问题

from django.utils.encoding import escape_uri_path
from django.http import HttpResponse

def download(request):
fn = "中文文件.xlsx" with open(fn, 'rb') as f:
content = f.read()

response
= HttpResponse(content) response['Content-Type'] = 'application/octet-stream' response['Content-Disposition'] = 'attachment;filename='{}'.format(escape_uri_path(fn)) return response

 

posted @ 2019-03-04 20:44  TimLinux  阅读(553)  评论(0)    收藏  举报