1
<?xml version="1.0"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><title>Twisted Documentation: Overview of Twisted Web</title><link href="../howto/stylesheet.css" type="text/css" rel="stylesheet" /></head><body bgcolor="white"><h1 class="title">Overview of Twisted Web</h1><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">
3
Web programming with Twisted Web
4
</a></li></ol></div><div class="content"><span></span><h2>Introduction<a name="auto0"></a></h2><p>Twisted Web is a web application server written in pure
5
Python, with APIs at multiple levels of abstraction to
6
facilitate different kinds of web programming.
7
</p><h2>Twisted Web's Structure<a name="auto1"></a></h2><p><img src="../img/web-overview.png" /></p><p>When
8
the Web Server receives a request from a Client, it creates
9
a Request object and passes it on to the Resource system.
10
The Resource system dispatches to the appropriate Resource
11
object based on what path was requested by the client. The
12
Resource is asked to render itself, and the result is
13
returned to the client.</p><h2>Resources<a name="auto2"></a></h2><p>Resources are the lowest-level abstraction for applications
14
in the Twisted web server. Each Resource is a 1:1 mapping with
15
a path that is requested: you can think of a Resource as a
16
single <q>page</q> to be rendered. The interface for making
17
Resources is very simple; they must have a method named
18
<code>render</code> which takes a single argument, which is the
19
Request object (an instance of <code class="API"><a href="http://twistedmatrix.com/documents/TwistedDocs/TwistedDocs-1.3.0/api/twisted.web.server.Request.html" title="twisted.web.server.Request">twisted.web.server.Request</a></code>). This render
20
method must return a string, which will be returned to the web
21
browser making the request. Alternatively, they can return a
22
special constant, <code class="API"><a href="http://twistedmatrix.com/documents/TwistedDocs/TwistedDocs-1.3.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
23
the web server not to close the connection; you must then use
24
<code class="python">request.write(data)</code> to render the
25
page, and call <code class="python">request.finish()</code>
28
Web programming with Twisted Web
29
<a name="auto3"></a></h2><p>
30
Web programmers seeking a higher level abstraction than the Resource system
31
should look at <a href="http://www.divmod.org/Home/Projects/Nevow/">Nevow</a>, available as
32
part of the <a href="http://www.divmod.org/Quotient/">Quotient</a> project. Nevow
33
is not distributed as part of Twisted.
35
Nevow is based on the same ideas as the earlier <a href="woven.html">Woven</a> framework.
36
Woven only remains part of Twisted in order to support existing projects, and should
37
not be used for new projects. Nevow is a simpler framework which retains the strengths of Woven.
38
</p></div><p><a href="../howto/index.html">Index</a></p><span class="version">Version: 1.3.0</span></body></html>
b'\\ No newline at end of file'