Changing an application's favicon in CherryPy

While it's technically simple, I found the documentation about changing the favicon of a CherryPy site to be somewhat confusing. This is my attempt to clear it up a bit.

There are two different ways of supplying config information:

  1. Config information from a text file (you can pass a filename or open file handle).
  2. Config information from a Python dictionary in your code.

I'm going to concentrate on the second method for now.

Here's my config dictionary.

~~~~ {.python name="code"} config = { '/': { 'log.error_file': os.path.join(os.path.dirname(__file__), 'site.log'), 'environment': 'production', }, '/favicon.ico': { 'tools.staticfile.on': True, 'tools.staticfile.filename': '/path/to/favicon.ico', }} wzxhzdk:0

Previously, we passed the '/' config parameters to cherrypy.config.update().

Now we pass the entire config dictionary along. This approach is nice because we can also store application configuration info (that CherryPy doesn't necessarily care about) and then get values out of it by using the cherrypy.request.app.config dictionary.

Another addition to this approach is to configure an area for serving static content (CSS, javascript, images, etc). That can easily be done by adding the following item to the config dictionary:

~~~~ {.python name="code"} '/static': { 'tools.staticdir.on': True, 'tools.staticdir.dir': os.path.join(os.path.dirname(__file__), 'static') }, wzxhzdk:1