bottle想輸出html,css,js,png這些靜態資源文件是非常簡單的,還是一個函數:static_file
使用方法:return static_file(文件名, root="文件所在目錄絕對路徑")
老規矩,給出demo:
~~~
# coding:UTF-8
from bottle import Bottle, static_file
app = Bottle()
@app.get('/')
def index():
return static_file("index.html", root="/var/ww/html")
app.run(host="127.0.0.1", port=8000, reloader=True, debug=True)
~~~