问题
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