how to use multiple dispatchers in same cherrypy application?

让人想犯罪 __ 提交于 2019-12-11 13:33:48

问题


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()

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.


回答1:


Since your Root is to be served with a normal dispatcher, it should be index.exposed = True.



来源:https://stackoverflow.com/questions/20965661/how-to-use-multiple-dispatchers-in-same-cherrypy-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!