如何在同一个Cherrypy应用程序中使用多个调度程序? [英] how to use multiple dispatchers in same cherrypy application?
问题描述
我有一个像这样的cherrypy应用程序:
I have a cherrypy application like this:
import cherrypy
from controllers import UsersController
class Root(object):
exposed = True
def index(self):
return 'welcome'
if __name__ == '__main__':
root = Root()
root.users = UsersController()
cherrypy.tree.mount(
root,
'/',
{
'/users' : {'request.dispatch' : cherrypy.dispatch.MethodDispatcher()}
}
)
cherrypy.engine.start()
cherrypy.engine.block()
现在,我希望使用MethodDispatcher()向/ users资源提供REST api,并且希望使用默认的调度程序来分配'/'路径(其中对root.index()的调用是预期)。除了编写自己的RoutesDispatcher()之外,还有什么方法可以实现? (例如,对所示的 / users使用MethodDispatcher(),对 /使用DefaultDispatcher()之类的东西)?顺便说一句,我得到的错误是'根'对象不可调用
。
Now I wish to use MethodDispatcher() for providing REST api to /users resource and I want a default dispatcher for '/' path (where a call to root.index() is expected). Instead of writing own RoutesDispatcher() is there any way to achieve this? (e.g. using MethodDispatcher() for '/users' as shown and something like DefaultDispatcher() for '/')? BTW, the error I am getting is 'Root' object is not callable
.
推荐答案
由于您的 Root
将由常规调度程序提供,因此应为 index.exposed = True
Since your Root
is to be served with a normal dispatcher, it should be index.exposed = True
.
这篇关于如何在同一个Cherrypy应用程序中使用多个调度程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!