我正在尝试使用他们网站上的示例来测试cherrypy框架:
import cherrypy
class HelloWorld(object):
def index(self):
return "Hello World!"
index.exposed = True
cherrypy.quickstart(HelloWorld())
当我运行它时,我在控制台中得到了这个响应:
[05/Dec/2011:00:15:11] ENGINE Listening for SIGHUP.
[05/Dec/2011:00:15:11] ENGINE Listening for SIGTERM.
[05/Dec/2011:00:15:11] ENGINE Listening for SIGUSR1.
[05/Dec/2011:00:15:11] ENGINE Bus STARTING
CherryPy Checker:
The Application mounted at '' has an empty config.
[05/Dec/2011:00:15:11] ENGINE Started monitor thread '_TimeoutMonitor'.
[05/Dec/2011:00:15:11] ENGINE Started monitor thread 'Autoreloader'.
[05/Dec/2011:00:15:12] ENGINE Serving on 127.0.0.1:8080
[05/Dec/2011:00:15:12] ENGINE Bus STARTED
当在本地运行浏览器并指向localhost:8080时,它在使用serverip时可以正常工作:8080它没有。我是否必须在某处设置服务器的IP地址?
答案 0 :(得分:11)
默认情况下,cherrypy.quickstart
仅绑定到localhost 127.0.0.1
,可以从服务计算机访问,但不能通过网络从连接到它的计算机访问。
如果您希望能够从另一台计算机访问该站点,则需要设置配置,如here中所述。
这是一个基本示例,只是更改cherrypy以绑定到所有网络接口。
import cherrypy
class HelloWorld(object):
def index(self):
return "Hello World!"
index.exposed = True
# bind to all IPv4 interfaces
cherrypy.config.update({'server.socket_host': '0.0.0.0'})
cherrypy.quickstart(HelloWorld())