gpt4 book ai didi

html - Django 重命名下载文件

转载 作者:行者123 更新时间:2023-12-02 22:05:24 25 4
gpt4 key购买 nike

在服务器中,文件名为“abc.dat”,但我想在人们下载时将文件重命名为“xyz.doc”。我的服务器是基于Django 的。

最佳答案

使用 Django 提供文件是通过在响应中设置它来完成的

然后您可以强制重命名附件的 filename= 属性。这真的可以是任何东西。

是这样实现的:

response = HttpResponse("read your file here ie. abc.dat", mimetype="application/msword")
response['Content-Disposition'] = 'attachment; filename=%s' % ("xyz.doc")
return response

希望对您有所帮助!

关于html - Django 重命名下载文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16209070/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com