Imported Upstream version 12.1.0
[contrib/python-twisted.git] / doc / web / howto / web-overview.html
1 <?xml version="1.0" encoding="utf-8"?><!DOCTYPE html  PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN'  'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'><html lang="en" xmlns="http://www.w3.org/1999/xhtml">
2   <head>
3 <title>Twisted Documentation: Overview of Twisted Web</title>
4 <link href="stylesheet.css" rel="stylesheet" type="text/css"/>
5   </head>
6
7   <body bgcolor="white">
8     <h1 class="title">Overview of Twisted Web</h1>
9     <div class="toc"><ol><li><a href="#auto0">Introduction</a></li><li><a href="#auto1">Twisted Web's Structure</a></li><li><a href="#auto2">Resources</a></li><li><a href="#auto3">
10         Web programming with Twisted Web
11     </a></li></ol></div>
12     <div class="content">
13     <span/>
14
15     <h2>Introduction<a name="auto0"/></h2>
16
17     <p>Twisted Web is a web application server written in pure
18     Python, with APIs at multiple levels of abstraction to
19     facilitate different kinds of web programming.
20     </p>
21
22     <h2>Twisted Web's Structure<a name="auto1"/></h2>
23
24         <p><img src="../img/web-overview.png"/></p>
25
26         <p>When
27         the Web Server receives a request from a Client, it creates
28         a Request object and passes it on to the Resource system.
29         The Resource system dispatches to the appropriate Resource
30         object based on what path was requested by the client. The
31         Resource is asked to render itself, and the result is
32         returned to the client.</p>
33
34     <h2>Resources<a name="auto2"/></h2>
35
36     <p>Resources are the lowest-level abstraction for applications
37     in the Twisted web server. Each Resource is a 1:1 mapping with
38     a path that is requested: you can think of a Resource as a
39     single <q>page</q> to be rendered. The interface for making
40     Resources is very simple; they must have a method named
41     <code>render</code> which takes a single argument, which is the
42     Request object (an instance of <code class="API"><a href="http://twistedmatrix.com/documents/12.1.0/api/twisted.web.server.Request.html" title="twisted.web.server.Request">twisted.web.server.Request</a></code>). This render
43     method must return a string, which will be returned to the web
44     browser making the request. Alternatively, they can return a
45     special constant, <code class="API"><a href="http://twistedmatrix.com/documents/12.1.0/api/twisted.web.server.NOT_DONE_YET.html" title="twisted.web.server.NOT_DONE_YET">twisted.web.server.NOT_DONE_YET</a></code>, which tells
46     the web server not to close the connection; you must then use
47     <code class="python">request.write(data)</code> to render the
48     page, and call <code class="python">request.finish()</code>
49     whenever you're done.
50     </p>
51
52     <h2>
53         Web programming with Twisted Web
54     <a name="auto3"/></h2>
55
56     <p>
57         Web programmers seeking a higher level abstraction than the Resource system
58         should look at <a href="https://launchpad.net/nevow" shape="rect">Nevow</a>.
59         Nevow is based on ideas previously developed in Twisted, but is now maintained
60         outside of Twisted to easy development and release cycle pressures.
61     </p>
62   </div>
63
64     <p><a href="index.html">Index</a></p>
65     <span class="version">Version: 12.1.0</span>
66   </body>
67 </html>