title: CherryPy : Accessing Global config
body: <p>I'm working on a CherryPy application based on what I found on that B<a href="https://bitbucket.org/Lawouach/twiseless/src" rel="nofollow">itBucket repository</a>.</p>
  
  <p>As in this example, there is two config files, server.cfg (aka "global") and app.cfg.</p>
  
  <p>Both config files are loaded in the <a href="https://bitbucket.org/Lawouach/twiseless/src/d171fde9e454/serve.py" rel="nofollow">serve.py</a> file :</p>
  
  <pre><code># 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's mount the application so that CherryPy can serve it
  app = cherrypy.tree.mount(webapp, '/', os.path.join(self.conf_path, "app.cfg"))
  </code></pre>
  
  <p>Now, I'd like to add the Database configuration.
  My first thought was to add it in the server.cfg (is this the best place? or should it be located in app.cfg ?).</p>
  
  <p>But if I add the Database configuration in the server.cfg, I don't know how to access it.
  Using :</p>
  
  <pre><code>cherrypy.request.app.config['Database']
  </code></pre>
  
  <p>Works only if the [Database] parameter is in the app.cfg.</p>
  
  <p>I tried to print cherrypy.request.app.config, and it shows me only the values defined in app.cfg, nothing in server.cfg.</p>
  
  <p>So I have two related question :</p>
  
  <ul>
  <li>Is it best to put the database connection in the server.cfg or app.cfg file</li>
  <li>How to access server.cfg configuration (aka global) in my code</li>
  </ul>
  
  <p>Thanks for your help! :)</p>