django excel xlsx 中文编码

django xlsx中文乱码问题解决:

详情: Python3.x在django中如何设置Content-Disposition,才能让浏览器正确保存中文命名的文件?

 

from django.utils.encoding import escape_uri_path
from django.http import HttpResponse
def test(request):
    file_name = '测试.txt'
    content = ...
    response = HttpResponse(content, content_type='application/octet-stream')
    response['Content-Disposition'] = "attachment; filename*=utf-8''{}".format(escape_uri_path(file_name))
    return response

 

posted @ 2018-06-25 20:52  leo_23  阅读(295)  评论(0编辑  收藏  举报