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

标签 python api web bottle

我目前正在开始使用 Bottle 框架(做 Hello World 示例,然后必须构建 RESTful API)。问题是重新加载器不起作用。当我对代码进行更改并重新加载页面时,更改应该显示没有任何反应。它可以在我 friend 的计算机上运行,​​所以我有点困惑。

使用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
----------------------------------------

最佳答案

an interesting clue如果您使用 Windows 操作系统:

Keep in mind that in windows this must be under if name == "main": due to the way the multiprocessing module works.

所以它应该看起来像这样

from bottle import route, run

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

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

关于python - 自动重新加载在 Bottle 框架中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41880747/

相关文章:

python - 使用 tweepy 搜索 API。但得到的结果比我在网站上搜索的要少得多。为什么?

python - 如何实现 Nadex 自动交易机器人?

javascript - 如何将来 self 正在使用的 API 的 JSON 响应分配给页面上的元素?

html - 如果标题是html,网站如何在每个页面上保留标题?

javascript - 当我不单击图像时如何停止声音播放?

java - 如何在 Java(REST) 应用程序中对用户进行身份验证?

python - 如何在 GUI 中嵌入外部窗口(Python + Glade + Gtk3)

python - 如何使用python从cloudformation堆栈字典中获取特定字段的值

python - 使用 openpyxl 在 excelsheet 中创建内部链接

python - Google Cloud Speech API python 代码示例可能存在错误