[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

浙公网安备 33010602011771号