Subsections
CherryPy sits between a compiler and an application server.
- Like a compiler, it reads input files and generates an executable. The executable contains everything to
run the website, including its own HTTP server.
- Like an application server, it delivers highly-dynamic web sites that can be linked to other ressources,
like a database for instance.
In a server generated by CherryPy, every request from a client (for instance, a browser requesting an URL)
is transformed into a call to the method of a class. The parameters sent by the client become the arguments of
the function.
With CherryPy, website developers just have to implement those classes and those methods. It doesn't matter if
the parameters are sent with a GET, a POST, if they're a short string or a large file that's being uploaded.
They're all converted to a regular Python string and passed as an argument to the method. It's all transparent
to the developer.
Input files for CherryPy are written using an extension to the Python language. This extension defines
some special classes called CherryClass. It also defines different types of methods for those
CherryClasses:
- functions: they are used to process some data. They are written in regular Python. Functions
typically take some data as input and return some data (as opposed to, say, HTML) as output.
- masks: they are used to render some data. They are written in CHTL or CGTL (which are CherryPy's templating
languages). Masks typically take some data as input and return HTML (or XML; Javascript, ...) as output.
- views: a view is written in regular Python. Views can be used in two different ways:
- they can be used like masks, to render some data. In this case, the only difference with masks is the language they're
written in. For instance, a page with lots of static data and only a little bit of dynamic data will be best written
as a mask (in CHTL or CGTL). A page with lots of dynamic data and only a bit of static data will be best written as
a view (in Python).
- they can be used as the link between a function and a mask. In this case, the source code of the view will typically be:
apply this mask to the result of that function
This concept of functions, masks and views used in CherryClasses is one of the main feature of CherryPy. A CherryClass can
contain all the information to process some data and to display the result, making it a self-contained module that
can be easily reused or sub-classed.
We've seen a few of the powerful concepts used in CherryPy. More concepts will be described later, but it's now
time to create our first website...
See About this document... for information on suggesting changes.