Does the MethodDispatcher from CherryPy handle multiple url paths? I'm trying to do something like below, but while requests to /customers work fine, requests to /orders always return '404 Nothing matches the given URI'.class Customers(object): exposed = True def GET(self): return getCustomers()class Orders(object): exposed = True def GET(self): return getOrders()class Root(object): passroot = Root()root.customers = Customers()root.orders = Orders()conf = { 'global': { 'server.socket_host': '0.0.0.0', 'server.socket_port': 8000, }, '/': { 'request.dispatch': cherrypy.dispatch.MethodDispatcher(), },}cherrypy.quickstart(root, '/', conf)推荐答案我认为我已经解决了,请尝试使用:I think I solved it, try using:cherrypy.tree.mount(Root())cherrypy.tree.mount(Customers(), '/customers', {'/': {'request.dispatch': cherrypy.dispatch.MethodDispatcher()} })cherrypy.tree.mount(Orders(), '/orders', {'/': {'request.dispatch': cherrypy.dispatch.MethodDispatcher()} })cherrypy.engine.start()cherrypy.engine.block()似乎要在 Root 类中公开方法,您必须使用注释 @ cherrypy.expose .设置 exposed = True 可能无效.It seems like in order to expose methods in Root class you have to use annotation @cherrypy.expose. Setting exposed = True probably won't work.请参阅我对自己问题的回答在单个CherryPy应用程序中将REST调度程序与默认调度程序相结合.See my answer to my own question Combining REST dispatcher with the default one in a single CherryPy app. 这篇关于具有多个URL路径的CherryPy MethodDispatcher的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-23 19:00