Python:如何提供文件

时间:2017-01-11 20:06:02

标签: python file download

我正在为自己做一个侧面项目,我想创建一个网页,基本上是一个按钮,可以下载文件(更具体地说是一个苹果钱包文件,但这并不重要) 。 前端侧没问题,但我在后端方面遇到了麻烦。我无法呈现可下载的文件。

这是我写的

@view_config(name='pkpass', request_method='POST')
def post_mobile(request):
   #i've shortened this for readability
   b64 = 'JIDEWJIODEW'
   b64decoded = base64.b64decode(b64)
   try :
      res = Response(body=b64decoded, content_type = 'application/octet-stream')
      res.content_disposition = 'attachment; filename="test.pkpass"'
   except Exception as e :
      print(e)

   return res

但是有一些我无法得到的东西。浏览器如何知道必须下载此文件?我的意思是,自动下载将如何开始?此外,当我点击我的链接时没有任何反应。我确保后端被正确调用,但我不确定返回值

PS:添加SC enter image description here 编辑2:HTML屏幕截图

enter image description here

0 个答案:

没有答案