使用Gunicorn的Bottle

6 投票
1 回答
5352 浏览
提问于 2025-04-27 12:21
from bottle import route, run

@route('/')
def index():
    return 'Hello!'

run(server='gunicorn', host='0.0.0.0', port=8080)
from bottle import route, default_app

@route('/')
def index():
    return 'Hello!'

app = default_app()

运行Bottle脚本时,这两种方式有什么区别呢?

第一种方式是用命令python app.py来启动你的应用。

第二种方式是用命令gunicorn app:app --bind='0.0.0.0:8080'来启动。

暂无标签

1 个回答

4

其实没什么特别的。

GunicornServer 的源代码来看,你可以在 这里 找到,基本的应用程序是用你提供的参数加载并运行的。而在 gunicorn 的源代码中,这里 是根据 setup.py 被 gunicorn 命令调用的内容。唯一的区别是使用了 WSGIApplication 类。至于 default_proc_name,它的值要么是 'app:app',要么是 'gunicorn',这取决于你用哪个来启动。其他的参数在这个简单的情况下并不重要。

撰写回答