我目前正在开始使用 Bottle 框架(做“Hello World”示例,然后必须构建 RESTful API)。问题是重新加载器不起作用。当我对代码进行更改并重新加载页面时,更改应该显示没有任何反应。它可以在我朋友的电脑上运行,所以我有点困惑。
使用Python 2.7。
from bottle import route, run
@route('/hello')
def hello():
return "Hello World!"
run(host='localhost', port=8080, debug=True, reloader =True)
编辑:我还注意到,当我在服务器仍在监听时保存脚本中的更改时,我得到了:
Exception happened during processing of request from ('127.0.0.1', 60472)
Traceback (most recent call last):
File "C:\Python27\lib\SocketServer.py", line 290, in _handle_request_noblock
self.process_request(request, client_address)
File "C:\Python27\lib\SocketServer.py", line 318, in process_request
self.finish_request(request, client_address)
File "C:\Python27\lib\SocketServer.py", line 331, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "C:\Python27\lib\SocketServer.py", line 652, in __init__
self.handle()
File "C:\Python27\lib\wsgiref\simple_server.py", line 116, in handle
self.raw_requestline = self.rfile.readline(65537)
File "C:\Python27\lib\socket.py", line 480, in readline
data = self._sock.recv(self._rbufsize)
KeyboardInterrupt
如果您使用 Windows 操作系统,有 一个有趣的线索:
请记住,在 Windows 中这必须是 在 if name == "main" 下:由于多处理的方式 模块有效。
所以它应该看起来像这样
from bottle import route, run
@route('/hello')
def hello():
return "Hello World!"
if __name__ == "__main__":
run(host='localhost', port=8080, debug=True, reloader=True)