简体   繁体   中英

Sample Bottle App (Python) gives 404 even though route is defined

I am just getting started with Bottle. I have found a sample app on GitHub . The sample just has a server.py file which looks like below

import bottle

APP = bottle.Bottle()

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

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

The requirements.txt file has

bottle
gunicorn

as dependencies. I am using Python 3.7.2. After running pip install -r requirements.txt, I ran python server.py. The server starts up without error on Port 8080

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

When I access http://localhost:8080, I get

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

Not found: '/'

Please let me know what's wrong with the setup.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM