Python Bottle 教程:无法获取 HelloWorld 示例的任何内容
我刚刚安装了Bottle,并把它放到了这个目录:/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3
然后我想运行一个HelloWorld的例子,具体步骤可以在这个链接找到。我打开了localhost:8080/hello
,但是页面上什么都没有。
>>> from bottle import route, run
>>>
>>> @route('/hello')
... def hello():
... return "Hello World!"
...
>>> run(host='localhost', port=8080, debug=True)
Bottle v0.13-dev server starting up (using WSGIRefServer())...
Listening on http://localhost:8080/
Hit Ctrl-C to quit.
我不知道为什么,请帮帮我!
2 个回答
0
如果在使用localhost的时候不行,但用127.0.0.1却可以,那说明你的网络设置可能有问题。
如果你是在Linux或Mac上,可以检查一下/etc/hosts这个文件,看看里面有没有:
127.0.0.1 localhost
在Windows上,这个文件的位置是%SystemRoot%\system32\drivers\etc\hosts。
如果里面没有这一行,就把它加上。
0
我也遇到过同样的问题。我把'localhost'换成了'127.0.0.1',结果却出现了404未找到的页面。不过,快速入门教程中的第二个例子是可以正常工作的:
from bottle import Bottle, run
app = Bottle()
@app.route('/hello')
def hello():
return "Hello World!"
run(app, host='localhost', port=8080)