Bottle 是一個快速、簡單且輕量級的 Python Web 框架,適合小型網站、原型開發與嵌入式 Web 服務。它幾乎不依賴外部套件,可直接在 Python 2.5+ 與 Python 3.x 環境中運行。
可直接下載單一檔案 bottle.py:
wget https://github.com/defnull/bottle/raw/master/bottle.py --no-check-certificate
from bottle import route, run
@route('/')
def hello():
return "Hello World!"
run(host='0.0.0.0', port=8080, debug=True)執行後,Bottle 會啟動內建 Web 伺服器,並在 8080 埠提供服務。瀏覽 https://127.0.0.1:8080/ 即可看到回應。
route() 是裝飾器,用來指定 URL 路徑;run() 則啟動內建伺服器。開發時可開啟 debug 模式,正式環境則應關閉。