Django 下载文件保存为中文

def downloadFile(request):
	name = '你好.txt'
	file = open("passages/文章.txt","rb")
	response = FileResponse(file)
	response['Content-Type'] = 'application/octet-stream'
	#response['Content-Disposition'] = 'attachment;filename="{0}"'.format(name.encode('utf8').decode('ISO-8859-1'))  这种方式也可以
	response['Content-Disposition'] = 'attachment;filename=%s' % name.encode('utf8').decode('ISO-8859-1')
	return response

自动弹出选择文件保存在哪,且保存时出现的文件名为中文

发布了147 篇原创文章 · 获赞 29 · 访问量 10万+

猜你喜欢

转载自blog.csdn.net/Haskei/article/details/89739363