Cherrypy返回NotFound:(404,"未找到路径'/'.")

mit*_*lsg 5 python cherrypy

我是新手,我正在尝试安装一个简单的hello world应用程序,但它一直返回"NotFound:(404,"路径'/'未找到.")",但我已定义它.

这是我得到的,

__ init __ .py中

import cherrypy
from HomeNetMain import HomeNetMain

cherrypy.config.update("global.cfg")
#I have tried "" for the script name parm but that doesn't work
cherrypy.tree.mount(HomeNetMain,"/","main.cfg") 
cherrypy.engine.start()
cherrypy.quickstart()
Run Code Online (Sandbox Code Playgroud)

在我的另一个文件中

import cherrypy

class HomeNetMain:

    @cherrypy.expose
    def index(self):
       return "Hello World"
Run Code Online (Sandbox Code Playgroud)

我已尝试使用decorator和index.exposed = True无效(子问题是装饰器或index.exposed的首选方法是什么)

global.cfg

[global]
server.socket_host: "127.0.0.1"
server.socket_port: 9080
log.screen: True
log.error_file: "/tmp/cherrypy.error"
log.access_file: "/tmp/cherrypy.access"
Run Code Online (Sandbox Code Playgroud)

main.cfg

[/]
log.screen: True
log.error_file: "/tmp/homenet.error"
log.access_file: "/tmp/homenet.access"
Run Code Online (Sandbox Code Playgroud)

我感谢任何帮助,提前谢谢.

编辑

这是完整的堆栈跟踪

Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/CherryPy-3.2.2-py2.7.egg/cherrypy/_cprequest.py", line 656, in respond
response.body = self.handler()
File "/usr/local/lib/python2.7/dist-packages/CherryPy-3.2.2-py2.7.egg/cherrypy/lib/encoding.py", line 188, in __call__
self.body = self.oldhandler(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/CherryPy-3.2.2-py2.7.egg/cherrypy/_cperror.py", line 386, in __call__
raise self
NotFound: (404, "The path '/' was not found.")
Run Code Online (Sandbox Code Playgroud)

mit*_*lsg 4

事实证明我不应该使用cherrypy.quickstart() 我将代码更改为以下内容并且工作正常

cherrypy.engine.start()
cherrypy.engine.block()
Run Code Online (Sandbox Code Playgroud)