Bottle:Python Web框架

Bottle 是一个快速,简单和轻量 WSGI Micro Web框架 Python. 它作为单个文件模块分发,除了 Python Standard Library .

  • 路由: 请求函数调用映射,支持干净和动态的URL。
  • 模板: 快速的和 Python 式的 built-in template engine 支持 mako, jinja2cheetah 模板。
  • 公用事业: 方便地访问表单数据、文件上载、cookie、头文件和其他与HTTP相关的元数据。
  • 服务器: 内置HTTP开发服务器并支持 paste, fapws3, bjoern, gae, cherrypy 或其他 WSGI 支持HTTP服务器。

例如:“你好,世界”在 Bottle 里

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)

运行此脚本或将其粘贴到Python控制台中,然后将浏览器指向 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的支持。

许可

根据MIT许可证提供代码和文档:

Copyright (c) 2009-2018, 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 的标志是 NOT 由该许可证覆盖。允许将该标识用作 Bottle 主页的链接或与未修改的类库直接关联的链接。其他情况请先问。

脚注

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