How do you access config outside of a request in CherryPy?

Posted by OrganicPanda on Stack Overflow See other posts from Stack Overflow or by OrganicPanda
Published on 2010-05-28T14:18:41Z Indexed on 2010/05/28 14:22 UTC
Read the original article Hit count: 252

Filed under:
|

I've got a webapp running on CherryPy that needs to access the CherryPy config files before a user creates a request. The docs say to use:

host = cherrypy.request.app.config['database']['host']

But that won't work outside of a user request. You can also use the application object when you start the app like so:

...
application = cherrypy.tree.mount(root, '/', app_conf)
host = application.config['database']['host']
...

But I can see no way of accessing 'application' from other classes outside of a user request.

I ask because our app looks at several databases and we set them up when the app starts rather than on user request. I have a feeling this would be useful in other places too; so is there any way to store a reference to 'application' somewhere or access it through the CherryPy API?

© Stack Overflow or respective owner

Related posts about python

Related posts about cherrypy