【问题标题】:Make file available for download outside working/project directory with bottle py使用 Bottle py 使文件在工作/项目目录之外可供下载
【发布时间】:2016-12-02 21:49:19
【问题描述】:

当文件位于文件系统根目录中时,如何使文件在瓶中可供下载。例如,在 ubuntu 操作系统的“媒体”目录中?

蟒蛇:

#bottle 0.12.10
@route('/download/<filename:path>')
def staticdownloadfile(filename):
    return bottle.static_file(filename, root='/media', download=filename)

html:

<a href="/static/media/somefile.extension">download here</a>

上述方法行不通? 404 未找到。

【问题讨论】:

    标签: python html download bottle


    【解决方案1】:

    在 html 文件中你应该使用另一个链接:

    <a href="/download/somefile.extension">download here</a>
    

    因为在应用中你已经定义了:

    @route('/download/<filename:path>')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-12
      • 2021-11-06
      • 2020-12-29
      • 1970-01-01
      • 2017-07-29
      • 1970-01-01
      • 2013-04-29
      • 2021-09-30
      相关资源
      最近更新 更多