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

使用模板或服务器适配器类需要相应的模板或服务器模块。