简体   繁体   中英

cherrypy.tree.mount and mod_wsgi

I used to use cherrypy with mod_python and I built my controller trees with cherrypy.tree.mount calls and I would like to keep them (they are spread through the code). Now I have to use mod_wsgi. Example: from 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)

My problem is that every cherrypy.tree.mount call creates a cherrypy.Application . And mod_wsgi wants one object named 'application' .

I know that you can build a cherrypy tree with class variables but I don't want to do that.

Is there a way to use cherrypy.tree.mount and get one application object?

There is also cherrypy.tree.graft but I think it's meant for a different purpose.

Finally! Got it myself - from the manual...

cherrypy.tree is itself a WSGI object so you simply do:

cherrypy.tree.mount(...)
cherrypy.tree.mount(...)
cherrypy.tree.mount(...)
application = cherrypy.tree

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM