自动重新加载在Bottle框架中不起作用

时间:2017-01-26 18:46:45

标签: python api web bottle

我目前正在开始使用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
----------------------------------------

1 个答案:

答案 0 :(得分:3)

如果您使用Windows操作系统,则有an interesting clue

  

请记住,在Windows中必须这样   如果名称 ==" 主要":由于多处理的方式   模块工作。

所以看起来应该是这样的

from bottle import route, run

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

if __name__ == "__main__":
    run(host='localhost', port=8080, debug=True, reloader=True)
相关问题