是否MethodDispatcher
from CherryPy
处理多个 url 路径?我正在尝试做类似下面的事情,但是虽然要求/customers
工作正常,要求/orders
始终返回“404 没有任何内容与给定的 URI 匹配”。
class Customers(object):
exposed = True
def GET(self):
return getCustomers()
class Orders(object):
exposed = True
def GET(self):
return getOrders()
class Root(object):
pass
root = 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)
我想我已经解决了,尝试使用:
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
可能行不通。
查看我对自己问题的回答将 REST 调度程序与单个 CherryPy 应用程序中的默认调度程序相结合 https://stackoverflow.com/questions/21536057/combining-rest-dispatcher-with-the-default-one-in-a-single-cherrypy-app/22475983#22475983.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)