9. Using several modules

As you'll program bigger websites, you'll soon feel the need to split your source code in several modules. There are two ways to do this:

What if the modules are not in the same directory ?

Well, all you have to do is to use the -I option to compile the files. This allows you to specify the directories where CherryPy will look for input files. For instance, if you have the following files:

/dir1/Module1.cpy
/dir2/Module2.cpy
Hello.cpy (uses Module1 and Module2)
Then you would compile Hello.cpy using:
python ../cherrypy.py -I /dir1 -I /dir2 Hello.cpy
By default, CherryPy will look in ., ../lib and ../src

You can also set an environment variable called CHERRYPY_HOME that contains the name of the directory where CherryPy is installed. In this case, CherryPy will also look in CHERRYPY_HOME/lib and CHERRYPY_HOME/src to find the modules.

In the next chapters, we'll learn how to use a few of CherryPy's standard library modules.

See About this document... for information on suggesting changes.