1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>2. Concepts used in CherryPy</title>
<META NAME="description" CONTENT="2. Concepts used in CherryPy">
<META NAME="keywords" CONTENT="tut">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="STYLESHEET" href="tut.css" type='text/css'>
<link rel="first" href="tut.html">
<link rel="contents" href="contents.html" title="Contents">
<LINK REL="next" HREF="node5.html">
<LINK REL="previous" HREF="node3.html">
<LINK REL="up" HREF="tut.html">
<LINK REL="next" HREF="node5.html">
<meta name='aesop' content='information'>
</head>
<body>
<DIV CLASS="navigation">
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A HREF="node3.html"><img src="../icons/previous.gif"
border="0" height="32"
alt="Previous Page" width="32"></A></td>
<td><A HREF="tut.html"><img src="../icons/up.gif"
border="0" height="32"
alt="Up One Level" width="32"></A></td>
<td><A HREF="node5.html"><img src="../icons/next.gif"
border="0" height="32"
alt="Next Page" width="32"></A></td>
<td align="center" width="100%">CherryPy Tutorial</td>
<td><A HREF="node2.html"><img src="../icons/contents.gif"
border="0" height="32"
alt="Contents" width="32"></A></td>
<td><img src="../icons/blank.gif"
border="0" height="32"
alt="" width="32"></td>
<td><img src="../icons/blank.gif"
border="0" height="32"
alt="" width="32"></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" HREF="node3.html">1. Downloading, installing and</A>
<b class="navlabel">Up:</b> <a class="sectref" HREF="tut.html">CherryPy Tutorial</A>
<b class="navlabel">Next:</b> <a class="sectref" HREF="node5.html">3. Creating a first</A>
<br><hr>
</DIV>
<!--End of Navigation Panel-->
<!--Table of Child-Links-->
<A NAME="CHILD_LINKS"><STRONG>Subsections</STRONG></a>
<UL CLASS="ChildLinks">
<LI><A href="node4.html#SECTION004100000000000000000">2.1 Creation of a website</a>
<LI><A href="node4.html#SECTION004200000000000000000">2.2 Handling of requests</a>
<LI><A href="node4.html#SECTION004300000000000000000">2.3 Programming a website</a>
</ul>
<!--End of Table of Child-Links-->
<HR>
<H1><A NAME="SECTION004000000000000000000">
2. Concepts used in CherryPy</A>
</H1>
<P>
<H1><A NAME="SECTION004100000000000000000">
2.1 Creation of a website</A>
</H1>
CherryPy sits between a compiler and an application server.
<UL>
<LI>Like a compiler, it reads input files and generates an executable. The executable contains everything to
run the website, including its own HTTP server.
</LI>
<LI>Like an application server, it delivers highly-dynamic web sites that can be linked to other ressources,
like a database for instance.
</LI>
</UL>
<P>
<H1><A NAME="SECTION004200000000000000000">
2.2 Handling of requests</A>
</H1>
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.
<P>
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.
<P>
<H1><A NAME="SECTION004300000000000000000">
2.3 Programming a website</A>
</H1>
Input files for CherryPy are written using an extension to the Python language. This extension defines
some special classes called <b>CherryClass</b>. It also defines different types of methods for those
CherryClasses:
<P>
<UL>
<LI><b>functions</b>: 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.
</LI>
<LI><b>masks</b>: 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.
</LI>
<LI><b>views</b>: a view is written in regular Python. Views can be used in two different ways:
<UL>
<LI>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).
</LI>
<LI>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:
<b>apply this mask to the result of that function</b>
</LI>
</UL>
</LI>
</UL>
<P>
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.
<P>
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...
<P>
<DIV CLASS="navigation">
<p><hr>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A HREF="node3.html"><img src="../icons/previous.gif"
border="0" height="32"
alt="Previous Page" width="32"></A></td>
<td><A HREF="tut.html"><img src="../icons/up.gif"
border="0" height="32"
alt="Up One Level" width="32"></A></td>
<td><A HREF="node5.html"><img src="../icons/next.gif"
border="0" height="32"
alt="Next Page" width="32"></A></td>
<td align="center" width="100%">CherryPy Tutorial</td>
<td><A HREF="node2.html"><img src="../icons/contents.gif"
border="0" height="32"
alt="Contents" width="32"></A></td>
<td><img src="../icons/blank.gif"
border="0" height="32"
alt="" width="32"></td>
<td><img src="../icons/blank.gif"
border="0" height="32"
alt="" width="32"></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" HREF="node3.html">1. Downloading, installing and</A>
<b class="navlabel">Up:</b> <a class="sectref" HREF="tut.html">CherryPy Tutorial</A>
<b class="navlabel">Next:</b> <a class="sectref" HREF="node5.html">3. Creating a first</A>
<hr>
<span class="release-info">Release 0.10, documentation updated on 19 March 2004.</span>
</DIV>
<!--End of Navigation Panel-->
<ADDRESS>
See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
</ADDRESS>
</BODY>
</HTML>
|