Bottle 简介
Bottle 是一个快速、简单且轻量级的 WSGI 微型 Python 网络框架。它以单一文件模块的形式发布,除了 Python 标准库外没有其他依赖。
提供路由、模板、表单数据、文件上传、Cookie等,内置 HTTP 开发服务器,并支持多种支持 WSGI 的 HTTP 服务器(例如 gunicorn、paste 或 cheroot)。
官方文档:https://bottlepy.org/docs/dev/
安装 Bottle 框架
pip install bottlehello world
创建一个 app.py 文件,执行 python app.py 运行 http://localhost:8080
from bottle import run, route
@route('/')
def index():
return 'hello world'
run(host='localhost', port=8080)run 方法
Bottle 通过 run 方法启动 HTTP 服务器,下面是 run 方法是几个参数。
run(host='localhost', port=8080, debug=True, reloader=True, server='paste')
# host 指定 IP,localhost 或者 127.0.0.1 是指定本地 IP,如果修改成 0.0.0.0 能够支持外网访问
# port 运行端口
# debug 表示是否开启调试模式
# reloader 表示是否支持热更新,即修改代码不需要重启启动服务器
# server 替换wsgi,默认是wsgiref,paste 第三方多线程服务器,通过 pip 安装