【问题标题】:Bottle and Python. Change format of a static_file while downloading瓶子和蟒蛇。下载时更改静态文件的格式
【发布时间】:2020-01-14 03:30:57
【问题描述】:

下午好。我正在尝试用瓶子下载文件。但它总是以 .html 格式下载它。如何将其更改为 .txt?非常感谢。我的代码如下:

@get('/api/v1/descargarHist/<id>')
def descargar (id):
directorio, fichero = Repo.recuperar_historial(id)
return static_file(fichero, root=directorio,download='{}.txt'.format(id))

无论我怎么努力,我都无法改变它。它总是将其下载为 .html 有没有办法做到这一点?

【问题讨论】:

    标签: python html bottle


    【解决方案1】:

    static_filetakes a mimetype parameter:

    return static_file(fichero, root=directorio, download='{}.txt'.format(id), mimetype='text/plain')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-31
      • 2011-06-07
      • 1970-01-01
      • 2015-10-25
      • 2012-07-28
      相关资源
      最近更新 更多