bottle想实现文件下载是非常简单的,还是一个函数:static_file
使用方法:return static_file(文件名, root="文件所在目录绝对路径", download=True)
老规矩,给出demo:
~~~
# coding:UTF-8
from bottle import Bottle, static_file
app = Bottle()
@app.get('/')
def index():
return static_file("index.zip", root="/var/ww/html", download=True)
app.run(host="127.0.0.1", port=8000, reloader=True, debug=True)
~~~