python – Cherrypy返回NotFound:(404,“未找到路径’/’.”)

前端之家收集整理的这篇文章主要介绍了python – Cherrypy返回NotFound:(404,“未找到路径’/’.”)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我是新手,我正在尝试安装一个简单的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()

在我的另一个文件

import cherrypy

class HomeNetMain:

    @cherrypy.expose
    def index(self):
       return "Hello World"

我已尝试使用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"

main.cfg

[/]
log.screen: True
log.error_file: "/tmp/homenet.error"
log.access_file: "/tmp/homenet.access"

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

编辑

这是完整的堆栈跟踪

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.")
最佳答案
结果我不应该使用cherrypy.quickstart()我将代码更改为以下,它工作正常

cherrypy.engine.start()
cherrypy.engine.block()
原文链接:https://www.f2er.com/python/439272.html

猜你在找的Python相关文章