Bottle : Python Web 框架?

Bottle 是一個快速、簡單、輕量級的 Python WSGI 微型 Web 框架。它只有一個文件,只依賴 Python 標準庫 。

  • URL映射(Routing): 將URL請求映射到Python函數,支持動態URL,且URL更簡潔。

  • 模板(Templates): 快速且pythonic的 內置模板引擎 ,同時支持 mako , jinja2cheetah 等模板。

  • 基礎功能(Utilities): 方便地訪問表單數據,上傳文件,使用cookie,查看HTTP元數據。

  • 服務器: 內置HTTP開發服務器并支持 paste, bjoern, gae, cherrypy 或任何其他 WSGI 功能強大的HTTP服務器。

示例: "Hello World"

from bottle import route, run, template

@route('/hello/<name>')
def index(name):
    return template('<b>Hello {{name}}</b>!', name=name)

run(host='localhost', port=8080)

將其保存為py文件并執行,用瀏覽器訪問 http://localhost:8080/hello/world 即可看到效果。就這么簡單!

下載和安裝

安裝最新的穩定版本 pip install bottle 或下載 `bottle.py`_ _(不穩定)進入項目目錄。沒有困難 1 python標準庫以外的依賴項。Bottle 支持**python 2.7和python 3** .

0.13 版后已移除: 此版本放棄了對python 2.5和2.6的支持。

用戶指南?

如果你有將Bottle用于Web開發的打算,請繼續看下去。如果這份文檔沒有解決你遇到的問題,盡管在 郵件列表 中吼出來吧(譯者注:用英文哦)。

知識庫?

收集文章,使用指南和HOWTO

開發和貢獻?

這些章節是為那些對Bottle的開發和發布流程感興趣的開發者準備的。

許可證?

代碼和文件皆使用MIT許可證:

Copyright (c) 2009-2022, Marcel Hellkamp.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

然而,許可證 不包含 Bottle的logo。logo用作指向Bottle主頁的連接,或未修改過的類庫。如要用于其它用途,請先請求許可。

腳注

1

使用模板或服務器適配器類需要相應的模板或服務器模塊。