本文主要包含的內容是Bottle框架介紹和安裝使用。
一、Bottle框架介紹
Bottle是一個快速小巧,輕量級的 WSGI 微型 web 框架。同時Bottle也是一個簡單高效的遵循WSGI的微型python Web框架。
說微型,是因為它只有一個文件,除Python標准庫外,它不依賴於任何第三方模塊。
URL映射(Routing):將 URL 請求映射到 Python 函數,使 URL 更簡潔。
模板(Templates):快速且 pythonic 的內置模板引擎 ,同時支持 mako, jinja2 和 cheetah 等模板。
基礎功能(Utilities):方便地訪問表單數據,上傳文件,使用 cookie,查看 HTTP 元數據。
開發服務器(Server):內置了開發服務器,且支持 paste, fapws3 , bjoern, Google App Engine,cherrypy 等符合 WSGI 標准的 HTTP 服務器。
官網地址為: http://www.bottlepy.org/docs/dev/index.html
官網教程: http://www.bottlepy.org/docs/dev/tutorial.html
二、安裝和使用
本地Windows安裝使用pip install bottle即可
Linux系統可以通過這種形式安裝 sudo apt-get install pip-bottle
簡單示例代碼(hello.py):
from bottle import route, run
@route('/hello')
def hello():
return "Hello World!"
run(host='localhost', port=8080, debug=True)
運行效果如圖: