CherryPy: global configuration access

I am working on a CherryPy application based on what I found on this B itBucket repository .

As in this example, there are two configuration files: server.cfg (aka "global") and app.cfg.

Both configuration files are loaded into the serve.py file :

# Update the global settings for the HTTP server and engine
cherrypy.config.update(os.path.join(self.conf_path, "server.cfg"))

# ...

# Our application
from webapp.app import Twiseless
webapp = Twiseless()
# Let mount the application so that CherryPy can serve it
app = cherrypy.tree.mount(webapp, '/', os.path.join(self.conf_path, "app.cfg"))

Now I would like to add a database configuration. My first thought was to add it to server.cfg (is this the best place? Or should it be located in app.cfg?).

But if I add the database configuration to server.cfg, I don’t know how to access it. Using:

cherrypy.request.app.config['Database']

It works only if the [Database] parameter is in app.cfg.

cherrypy.request.app.config, , app.cfg, server.cfg.

, :

  • server.cfg app.cfg.
  • server.cfg(aka global)

!:)

+3
1

. , , , - " /blogs , ?" , . , .

, , [Database]. . , , "database_port". : cherrypy.config.get("database_port").

+3

All Articles