| 1 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
|---|
| 2 |
|
|---|
| 3 |
<html xmlns="http://www.w3.org/1999/xhtml"> |
|---|
| 4 |
|
|---|
| 5 |
<head> |
|---|
| 6 |
<title>CherryPy tutorial</title> |
|---|
| 7 |
|
|---|
| 8 |
<meta name="generator" content="S5" /> |
|---|
| 9 |
<meta name="version" content="S5 1.1b5" /> |
|---|
| 10 |
<meta name="presdate" content="20050628" /> |
|---|
| 11 |
<meta name="author" content="Remi Delon" /> |
|---|
| 12 |
|
|---|
| 13 |
<meta name="defaultView" content="slideshow" /> |
|---|
| 14 |
<meta name="controlVis" content="hidden" /> |
|---|
| 15 |
|
|---|
| 16 |
<link rel="stylesheet" href="s5/theme/slides.css" type="text/css" media="projection" id="slideProj" /> |
|---|
| 17 |
<link rel="stylesheet" href="s5/default/outline.css" type="text/css" media="screen" id="outlineStyle" /> |
|---|
| 18 |
<link rel="stylesheet" href="s5/default/print.css" type="text/css" media="print" id="slidePrint" /> |
|---|
| 19 |
<link rel="stylesheet" href="s5/default/opera.css" type="text/css" media="projection" id="operaFix" /> |
|---|
| 20 |
|
|---|
| 21 |
<script src="s5/default/slides.js" type="text/javascript"></script> |
|---|
| 22 |
</head> |
|---|
| 23 |
<body> |
|---|
| 24 |
|
|---|
| 25 |
<div class="layout"> |
|---|
| 26 |
<div id="controls"></div> |
|---|
| 27 |
<div id="currentSlide"></div> |
|---|
| 28 |
<div id="header"></div> |
|---|
| 29 |
<div id="footer"> |
|---|
| 30 |
<h1>CherryPy tutorial</h1> |
|---|
| 31 |
<h2>EuroPython 2005</h2> |
|---|
| 32 |
</div> |
|---|
| 33 |
</div> |
|---|
| 34 |
|
|---|
| 35 |
<div class="presentation"> |
|---|
| 36 |
|
|---|
| 37 |
<div class="slide"> |
|---|
| 38 |
<h1>CherryPy tutorial</h1> |
|---|
| 39 |
<h3>Remi Delon</h3> |
|---|
| 40 |
<h4>remi@cherrypy.org</h4> |
|---|
| 41 |
<h4><a href="http://www.cherrypy.org/" rel="external">http://www.cherrypy.org</a></h4> |
|---|
| 42 |
<div class="handout"></div> |
|---|
| 43 |
</div> |
|---|
| 44 |
|
|---|
| 45 |
<div class="slide"> |
|---|
| 46 |
<h1>Introduction</h1> |
|---|
| 47 |
<ul> |
|---|
| 48 |
<li>Pythonic, object-oriented web development framework</li> |
|---|
| 49 |
<li>Runs everywhere python runs</li> |
|---|
| 50 |
<li>Requires Python-2.3 or later</li> |
|---|
| 51 |
<li>BSD license</li> |
|---|
| 52 |
<li>Version 2.1 (used in this tutorial) coming soon</li> |
|---|
| 53 |
</ul> |
|---|
| 54 |
</div> |
|---|
| 55 |
|
|---|
| 56 |
<div class="slide"> |
|---|
| 57 |
<h1>Brief history of CherryPy</h1> |
|---|
| 58 |
<ul> |
|---|
| 59 |
<li>Jun 2002: CherryPy-0.1 released: users wrote .cpy files made of python code + some extensions (ex: CherryClass), then compiled them into one .py file ... bad idea (too unpythonic) ... some interest, but quite limited</li> |
|---|
| 60 |
<li>Apr 2004: Last "CP1" release</li> |
|---|
| 61 |
<li>Sep 2004: First "CP2" release: pure python code, no more compilation step, templating system separated from the core ... much more interest from the community</li> |
|---|
| 62 |
<li>In a few weeks: CherryPy-2.1 release ... another big step forward</li> |
|---|
| 63 |
</ul> |
|---|
| 64 |
</div> |
|---|
| 65 |
|
|---|
| 66 |
<div class="slide"> |
|---|
| 67 |
<h1>Hello, world</h1> |
|---|
| 68 |
<ul> |
|---|
| 69 |
<li>Exposing objects</li> |
|---|
| 70 |
<li>Built-in HTTP server</li> |
|---|
| 71 |
<li>"development" environment: autoreload, debug information |
|---|
| 72 |
</ul> |
|---|
| 73 |
</div> |
|---|
| 74 |
|
|---|
| 75 |
<div class="slide"> |
|---|
| 76 |
<h1>Hello, you</h1> |
|---|
| 77 |
<ul> |
|---|
| 78 |
<li>Passing parameters to methods</li> |
|---|
| 79 |
<li>All parameters (except file uploads) are passed a strings or lists of strings</li> |
|---|
| 80 |
<li>GET or POST parameters are passed the same way</li> |
|---|
| 81 |
</ul> |
|---|
| 82 |
</div> |
|---|
| 83 |
|
|---|
| 84 |
<div class="slide"> |
|---|
| 85 |
<h1>Configuring CherryPy</h1> |
|---|
| 86 |
<ul> |
|---|
| 87 |
<li>Through config file</li> |
|---|
| 88 |
<li>Programmatically</li> |
|---|
| 89 |
</ul> |
|---|
| 90 |
</div> |
|---|
| 91 |
|
|---|
| 92 |
|
|---|
| 93 |
<div class="slide"> |
|---|
| 94 |
<h1>Url -> object mapping</h1> |
|---|
| 95 |
<ul> |
|---|
| 96 |
<li>Using multiple methods</li> |
|---|
| 97 |
<li>Using multiple classes</li> |
|---|
| 98 |
<li>Using the "default" method</li> |
|---|
| 99 |
<li>Using positional arguments for REST URLs</li> |
|---|
| 100 |
</ul> |
|---|
| 101 |
</div> |
|---|
| 102 |
|
|---|
| 103 |
<div class="slide"> |
|---|
| 104 |
<h1>Using OOP</h1> |
|---|
| 105 |
<ul> |
|---|
| 106 |
<li>Example: using OOP to provide a constant header/footer</li> |
|---|
| 107 |
</ul> |
|---|
| 108 |
</div> |
|---|
| 109 |
|
|---|
| 110 |
<div class="slide"> |
|---|
| 111 |
<h1>Handling file uploads</h1> |
|---|
| 112 |
<ul> |
|---|
| 113 |
<li>File is stored on disk as a temp file</li> |
|---|
| 114 |
<li>CherryPy returns a cgi.FieldStorage instance</li> |
|---|
| 115 |
<li>Available attributes: file, filename, type, ...</li> |
|---|
| 116 |
</ul> |
|---|
| 117 |
</div> |
|---|
| 118 |
|
|---|
| 119 |
<div class="slide"> |
|---|
| 120 |
<h1>Manipulating cpg.request and cpg.response</h1> |
|---|
| 121 |
<ul> |
|---|
| 122 |
<li>Ex: Reading the Host header from the request</li> |
|---|
| 123 |
<li>Ex: Setting the response Content-Type</li> |
|---|
| 124 |
</ul> |
|---|
| 125 |
</div> |
|---|
| 126 |
|
|---|
| 127 |
<div class="slide"> |
|---|
| 128 |
<h1>Using generators</h1> |
|---|
| 129 |
<ul> |
|---|
| 130 |
<li>Returning a generator instead of a string</li> |
|---|
| 131 |
<li>Returning a file object</li> |
|---|
| 132 |
<li>Set Content-Length manually to stream data to the browser "on-the-fly"</li> |
|---|
| 133 |
</ul> |
|---|
| 134 |
</div> |
|---|
| 135 |
|
|---|
| 136 |
<div class="slide"> |
|---|
| 137 |
<h1>Using filters</h1> |
|---|
| 138 |
<ul> |
|---|
| 139 |
<li>Ex: gzipFilter (uses generators)</li> |
|---|
| 140 |
<li>Ex: encodingFilter, decodingFilter</li> |
|---|
| 141 |
<li>Ex: staticContentFilter</li> |
|---|
| 142 |
<li>Other filters: XML-RPC, Tidy, nsgmls, virtual host, caching, ...</li> |
|---|
| 143 |
</ul> |
|---|
| 144 |
</div> |
|---|
| 145 |
|
|---|
| 146 |
<div class="slide"> |
|---|
| 147 |
<h1>Using sessions</h1> |
|---|
| 148 |
<ul> |
|---|
| 149 |
<li>Sessions are just a regular filter (sessionFilter)</li> |
|---|
| 150 |
<li>Provides dictionary-like objects for storing session data</li> |
|---|
| 151 |
<li>The default one is cherrypy.sessions.default</li> |
|---|
| 152 |
</ul> |
|---|
| 153 |
</div> |
|---|
| 154 |
|
|---|
| 155 |
<div class="slide"> |
|---|
| 156 |
<h1>Deploying your site for production</h1> |
|---|
| 157 |
<ul> |
|---|
| 158 |
<li>Built-in HTTP server: OK, but no HTTP/1.1 or SSL (yet)</li> |
|---|
| 159 |
<li>WSGI interface allows us to use a variety of setups: mod_python, FastCGI, IIS, ...</li> |
|---|
| 160 |
<li>Another option: behind Apache with mod_rewrite or mod_proxy (use Apache to serve static data directly)</li> |
|---|
| 161 |
</ul> |
|---|
| 162 |
</div> |
|---|
| 163 |
|
|---|
| 164 |
<div class="slide"> |
|---|
| 165 |
<h1>What's not included in CherryPy</h1> |
|---|
| 166 |
<ul> |
|---|
| 167 |
<li>A form handling module</li> |
|---|
| 168 |
<li>A templating system</li> |
|---|
| 169 |
<li>An authentication system</li> |
|---|
| 170 |
<li>... CherryPy is deliberately staying low-level</li> |
|---|
| 171 |
<li>... If you need a higher-level framework, consider Subway or CherryObject (coming soon)</li> |
|---|
| 172 |
</ul> |
|---|
| 173 |
</div> |
|---|
| 174 |
|
|---|
| 175 |
<div class="slide"> |
|---|
| 176 |
<h1>References</h1> |
|---|
| 177 |
<ul> |
|---|
| 178 |
<li>http://www.cherrypy.org</li> |
|---|
| 179 |
<li>Documentation: tutorial, FAQ, recipes, ...</li> |
|---|
| 180 |
<li>Mailing lists</li> |
|---|
| 181 |
<li>IRC channel: #cherrypy on OFTC</li> |
|---|
| 182 |
</ul> |
|---|
| 183 |
|
|---|
| 184 |
<div class="slide"> |
|---|
| 185 |
<h1>Near future of CherryPy</h1> |
|---|
| 186 |
<ul> |
|---|
| 187 |
<li>CherryPy-2.1 coming out soon (*lots* of new features)</li> |
|---|
| 188 |
<li>CherryPy book (online only for now) coming soon</li> |
|---|
| 189 |
<li>Lots of activity at the moment ... More and more contributors</li> |
|---|
| 190 |
<li>But we could still use more: feel free to help :-)</li> |
|---|
| 191 |
</ul> |
|---|
| 192 |
</div> |
|---|
| 193 |
|
|---|
| 194 |
|
|---|
| 195 |
<div class="slide"> |
|---|
| 196 |
<h1>Any questions ?</h1> |
|---|
| 197 |
</div> |
|---|
| 198 |
|
|---|
| 199 |
</div> |
|---|
| 200 |
|
|---|
| 201 |
</body> |
|---|
| 202 |
</html> |
|---|