【发布时间】:2023-03-11 12:17:01
【问题描述】:
我正在尝试运行此 website 上提供的示例
我的代码是这样的
#!/usr/bin/env python3
from bottle import route, run
@route('/cars')
def getcars():
cars = [ {'name': 'Audi', 'price': 52642},
{'name': 'Mercedes', 'price': 57127},
{'name': 'Skoda', 'price': 9000},
{'name': 'Volvo', 'price': 29000},
{'name': 'Bentley', 'price': 350000},
{'name': 'Citroen', 'price': 21000},
{'name': 'Hummer', 'price': 41400},
{'name': 'Volkswagen', 'price': 21600} ]
return dict(data=cars)
run(host='localhost', port=8080, debug=True)
当我运行 python run.py 并登录到http://localhost:8080/cars。我收到 404 错误。当我运行以下示例时,我得到相同的 404 错误
#!/usr/bin/env python3
from bottle import route, run
@route('/message')
def hello():
return "Today is a beautiful day"
run(host='localhost', port=8080, debug=True)
我错过了什么?
【问题讨论】:
-
这适用于 python3.6.2
-
我实际使用的是 3.7
-
它也适用于 3.7。您确定(抱歉)在 url 末尾写 /cars 吗? (也许您单击控制台中没有它的链接)。控制台打印什么?
-
我在vs code中使用了集成终端。那没起效。当我在 Win 10 中使用普通终端窗口时它可以工作
-
也许它正在调用一个没有安装瓶子的不同 python 版本......
标签: python python-3.6 bottle