[404为Cherrypy服务的路径

问题描述 投票:0回答:1

对于三个简单的应用程序:让我们使用不同于8080的端口:

cherrypy.config.update({'server.socket_host': '127.0.0.1',
                    'server.socket_port': 28130
                   })

让我们设置三个应用程序:

fusionConf = {'/ fusion':{}}mobileConf = {r“ / mobile_to_fusion”:{}}adminConf = {'/ admin':{}}

cherrypy.tree.mount(fusionListener,r“ / fusion”,fusionConf)cherrypy.tree.mount(mobileListener,r“ / mobile_to_fusion”,mobileConf)cherrypy.tree.mount(adminListener,r“ / admin”,adminConf)#

cherrypy.engine.start()cherrypy.engine.block()

我们可以看到它在正确的端口上运行:

$netstat -an | grep 28130
tcp4       0      0  127.0.0.1.28130        *.*                    LISTEN

应用程序日志记录同意:

CherryPy Checker:
The application mounted at '/fusion' has config entries that start with its script name: '/fusion'

CherryPy Checker:
The application mounted at '/mobile_to_fusion' has config entries that start with its script name: '/mobile_to_fusion'

CherryPy Checker:
The application mounted at '/admin' has config entries that start with its script name: '/admin'

但是访问URL:http://localhost:28130/admin-找不到吗?

404 Not Found
The path '/admin' was not found.

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/cherrypy/_cprequest.py", line 638, in respond
    self._do_respond(path_info)
  File "/usr/local/lib/python3.8/site-packages/cherrypy/_cprequest.py", line 697, in _do_respond
    response.body = self.handler()
  File "/usr/local/lib/python3.8/site-packages/cherrypy/lib/encoding.py", line 219, in __call__
    self.body = self.oldhandler(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/cherrypy/_cperror.py", line 416, in __call__
    raise self
cherrypy._cperror.NotFound: (404, "The path '/admin' was not found.")
Powered by CherryPy 18.5.0

enter image description here

为什么Cherrypy找不到路径?

python cherrypy
1个回答
0
投票

AdminListener类安装在/admin下,并且AdminListener没有defaultindex方法,因此无法将AdminListener的实例安装在/admin下并希望它可以工作。例如,在您当前的实现中,/admin/admin应该可以使用。

© www.soinside.com 2019 - 2024. All rights reserved.