CherryPy Project Download


This is a HOWTO. See BehindApache for a higher-level discussion.

A very simple setup lets your cherry run under SCGI (on apache in my setup). You need just a running apache server with mod_scgi and have the scgi python module installed. You also need an SCGI front end to WSGI. In this case, I'm using the SCGI-->WSGI application proxy, aka "SWAP" from Python Paste. Here's a direct link to SWAP. If that link doesn't work, you may have to hunt down SWAP on your own.


import cherrypy
from paste.util.scgiserver import serve_application

class HelloWorld:
    def index(self):
        return "Hello world!" = True

app = cherrypy.tree.mount(HelloWorld())
serve_application(application=app, prefix="/dynamic", port=4000)

The Apache configuration that goes along with this is as follows:

<Location "/dynamic">
    SCGIServer 4000
    SCGIHandler On

Older versions


This example uses the VirtualPathFilter? (not needed in CP 3); feel free to ignore it if you don't need it.


import cherrypy
from virtualpathfilter import VirtualPathFilter
from cherrypy._cpwsgi import wsgiApp
from paste.util.scgiserver import serve_application

class HelloWorld:
    """ Sample request handler class. """
    _cpFilterList = [VirtualPathFilter()]

    def index(self):
        return "Hello world!" = True

cherrypy.root = HelloWorld()
    '/': {
        'server.environment': 'development',
        'virtualPathFilter.on': True,
        'virtualPathFilter.prefix': "/dynamic"

# init cp
cherrypy.server.start(initOnly=True, serverClass=None)

# run the server
serve_application(application=wsgiApp, prefix="/dynamic", port=4000)

Hosted by WebFaction

Log in as guest/cherrypy to create/edit wiki pages