Python Bottle Tutorial: cannot get anything from the HelloWorld example

孤者浪人 提交于 2019-12-13 18:26:39

问题


I just installed Bottle and add it into this directory: /Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3

And when I was trying to run the HelloWorld example in http://bottlepy.org/docs/dev/tutorial.html#installation and opened localhost:8080/hello , there was nothing on the page.

>>> 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.

I don't know why, please help!


回答1:


I had the same problem. Replaced 'localhost' with '127.0.0.1' and got a 404 Not Found page. However, the second example in the quickstart tutorial worked:

from bottle import Bottle, run

app = Bottle()

@app.route('/hello')
def hello():
    return "Hello World!"

run(app, host='localhost', port=8080)



回答2:


If its not working with localhost but it is working with 127.0.0.1, it means your network configuration is not really set up correctly.

If you are on linux or mac, check the /etc/hosts file and look for:

127.0.0.1 localhost

Windows has the same file at %SystemRoot%\system32\drivers\etc\hosts.

If the row is not there, add it.



来源:https://stackoverflow.com/questions/25079529/python-bottle-tutorial-cannot-get-anything-from-the-helloworld-example

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!