在我的 Virtualenv 中创建了一个“Hello, World!” 用于测试 Gunicorn 的 web 应用程序。
这是我正在使用的代码:
def app(environ, start_response):
data = "Hello, World!\n"
start_response("200 OK", [
("Content-Type", "text/plain"),
("Content-Length", str(len(data)))
])
return iter([data])
当我访问(http://127.0.0.1:8000)时,它清楚地输出:“你好,世界!” 正如它应该做的那样。但是一旦我将数据字符串更改为:data = "This is an edit!"
并刷新浏览器,它仍然显示:“Hello, World!”。我的结论;看起来我每次更改代码后都必须重新启动 Gunicorn,这在开发环境中工作时真的很痛苦。
有没有办法解决这个问题?
当我执行 cat 命令时,它会正确显示代码:
(web)sl@cker:~/Envs/web/myapp$ cat myapp.py
def app(environ, start_response):
data = "This is an edit!"
start_response("200 OK", [
("Content-Type", "text/plain"),
("Content-Length", str(len(data)))
])
return iter([data])
我使用此命令启动服务器:gunicorn -w 4 myapp:app