在cherrypy中,有没有一种方法可以将该功能公开foo_test()
为/foo/test
服务器上的端点?
下面的例子暴露了两个端点/index
和/foo_test
:
class Test(object):
@cherrypy.expose
def index(self):
@cherrypy.expose
def foo_test(self):
笔记:
@cherrypy.expose(['foo/test'])
但是别名只允许使用字符串和字符串列表。最后,我不得不_cp_dispatch
按照http://docs.cherrypy.org/en/latest/advanced.html#the-special-cp-dispatch-method中的说明进行覆盖
class Test(object):
def __init__(self):
self.foo = Foo()
def _cp_dispatch(self, vpath):
if len(vpath) == 1:
return self
if len(vpath) == 2:
return self.foo
return self
@cherrypy.expose
def index(self):
class Foo(object):
@cherrypy.expose
def test(self):
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句