【问题标题】:Sample Bottle App (Python) gives 404 even though route is defined即使定义了路线,示例瓶应用程序(Python)也会给出 404
【发布时间】:2021-01-04 10:45:33
【问题描述】:

我刚刚开始使用 Bottle。我在GitHub 上找到了一个示例应用程序。该示例只有一个 server.py 文件,如下所示

import bottle

APP = bottle.Bottle()

@APP.get('/')
def index():
  return '<p>Hello</p>'

if __name__ == '__main__':
  bottle.run(application=APP)

requirements.txt 文件有

bottle
gunicorn

作为依赖项。我正在使用 Python 3.7.2。运行 pip install -r requirements.txt 后,我​​运行了 python server.py。服务器在端口 8080 上正常启动

Bottle v0.12.18 server starting up (using WSGIRefServer(application=<bottle.Bottle object at 0x1040fa2d0>))...
Listening on http://127.0.0.1:8080/

当我访问 http://localhost:8080 时,我得到了

Error: 404 Not Found
Sorry, the requested URL 'http://localhost:8080/' caused an error:

Not found: '/'

请告诉我设置有什么问题。

【问题讨论】:

    标签: python python-3.x bottle


    【解决方案1】:

    只需将 bottle.run(application=APP) 应用程序参数名称替换为应用程序 bottle.run(app=APP)

    【讨论】:

    • 我可以使用 python server.py 运行应用程序。我如何使用 gunicorn 运行它? gunicorn -w 2 server:app 对我不起作用。请告诉我
    • 未能在“服务器”中找到应用程序对象“应用程序”。这是我得到的错误
    • 使用bottle.run(app=APP,server="gunicorn",workers=2)
    • 是否可以不修改应用启动服务器?
    猜你喜欢
    • 2014-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多