@route('/hello/') on the bottle, but the top page is 404

Asked 2 years ago, Updated 2 years ago, 106 views

http://localhost:8080/ and http://127.0.0.1:8080/ have tried to access, but the following error appears:

Error: 404 Not Found
Sorry, the requested URL 'http://127.0.0.1:8080/ 'cause an error:
Not found: '/'

Log displayed at the command prompt:

127.0.0.1 - [21/Jul/2016 16:57:36] "GET/HTTP/1.1" 404720
127.0.0.1 - [21/Jul/2016 16:58:27] "GET/HTTP/1.1" 404720
127.0.0.1 - [21/Jul/2016 16:58:48] "GET/HTTP/1.1" 404720
127.0.0.1 - [21/Jul/2016 16:59:07] "GET/HTTP/1.1" 404720
127.0.0.1 - [21/Jul/2016 16:59:07] "GET/favicon.ico HTTP/1.1" 404 742
127.0.0.1 - [21/Jul/2016 17:32:18] "GET/HTTP/1.1" 404720
127.0.0.1 - [21/Jul/2016 17:32:18] "GET/favicon.ico HTTP/1.1" 404 742

」hello.py の contains the following:

 from bottle import route, run, template

@route('/hello/')
def index(name):
    return template ('Hello {{name}}!', name=name)

run (host='0.0.0.0', port=8080)

I tried the browser on both Google Chrome and Microsoft Edge.
I installed Windows 7, anaconda, and I use python3.
I would appreciate it if you could tell me the possible causes and solutions in detail.
Thank you for your cooperation.

python bottle

2022-09-29 21:44

1 Answers

def index(name): because we have prepared a function that takes the name as an argument, we think it should be @route('/hello/<name>').
Also, I think the function name should be def hello(name):.
After the change, the URL to access, for example, http://127.0.0.1:8080/hello/yasa.


2022-09-29 21:44

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.