在网上找到了解决方案,使用下面的代码,文件名成功显示了中文。

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

相关文章:

  • 2022-01-19
  • 2021-08-31
  • 2021-10-04
  • 2022-12-23
  • 2021-05-16
  • 2021-05-03
  • 2021-12-10
  • 2022-02-07
猜你喜欢
  • 2022-12-23
  • 2021-11-10
  • 2021-12-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-30
相关资源
相似解决方案