cherrypy.tree.mount和mod_wsgi

tau*_*ran 4 python apache mod-wsgi cherrypy

我过去常常使用带有mod_python的cherrypy,我用cherrypy.tree.mount调用构建我的控制器树,我想保留它们(它们通过代码传播).现在我必须使用mod_wsgi.示例:来自cherrypy wiki

import sys
sys.stdout = sys.stderr

import atexit
import threading
import cherrypy

cherrypy.config.update({'environment': 'embedded'})

if cherrypy.__version__.startswith('3.0') and cherrypy.engine.state == 0:
    cherrypy.engine.start(blocking=False)
    atexit.register(cherrypy.engine.stop)

class Root(object):
    def index(self):
        return 'Hello World!'
    index.exposed = True

application = cherrypy.Application(Root(), script_name=None, config=None)
Run Code Online (Sandbox Code Playgroud)

我的问题是每次cherrypy.tree.mount通话都会产生一个cherrypy.Application.mod_wsgi想要一个名为的对象'application'.

我知道你可以用类变量构建一个樱桃树,但我不想这样做.

有没有办法使用cherrypy.tree.mount并获得一个应用程序对象?

还有cherrypy.tree.graft,但我认为这是出于不同的目的.

tau*_*ran 9

最后!得到它自己 - 从手册...

cherrypy.tree 它本身就是一个WSGI对象,所以你只需:

cherrypy.tree.mount(...)
cherrypy.tree.mount(...)
cherrypy.tree.mount(...)
application = cherrypy.tree
Run Code Online (Sandbox Code Playgroud)