search

Home  >  Q&A  >  body text

python - 怎么让我的flask网站提供下载功能

背景:跟着狗书做了flask搭建的网站,后来给网站添加了爬取某琴谱网站的图片并转换成PDF的功能,实现了用户搜索关键字就能把结果发送PDF到邮箱的功能。

需求:想添加一个下载的按钮,用户只要点击就可以下载生成的PDF,但是在网上找了半天也没有搜到想要的答案,想知道这个功能通过那些模块能够实现?或者是flask本身就具有这种功能

ps:隐约感觉可能跟API有关。。。

PHPzPHPz2893 days ago380

reply all(2)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-04-18 09:44:56

    You can send it via email, assuming the file is in memory and is not large.

    response = make_response(content)
    response.headers["Content-Disposition"] = "attachment; filename=xxx.pdf"
    response.headers["Content-Type"] = "application/pdf"
    return response

    reply
    0
  • 高洛峰

    高洛峰2017-04-18 09:44:56

    Has the website been made? Take a look

    reply
    0
  • Cancelreply