如何在响应中设置文件名 [英] How to set file name in response

查看:80
本文介绍了如何在响应中设置文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解内容处理,但我阅读了它用于电子邮件的内容.我想知道如何使用内容类型设置文件名.ps 我用的是 Pyramid 框架

I know about content-disposition but I read what it uses for email messages. And I want to know how I can set file name with content-type. ps I use Pyramid framework

网站也有按钮下载"如何为文件名执行响应对象,如

edit: Web site has button 'download' how to perform Response object for file name too, like

return Response(body=f.read(), content_type='application/octet-stream')

以及我需要做什么才能在浏览器中显示正确的文件名.

and what I need to do for showing correct file name in browser.

推荐答案

您需要像这样设置 Content-Disposition 标题的文件名参数:

You need to set the filename parameter of the Content-Disposition header like so:

response.content_disposition = 'attachment; filename="my_filename.txt"'

这篇关于如何在响应中设置文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆