This file is indexed.

/usr/share/doc/python-twisted-web/howto/web-development.html is in python-twisted-web 13.2.0-1ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
<?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">
  <head>
<title>Twisted Documentation: Web Application Development</title>
<link href="stylesheet.css" rel="stylesheet" type="text/css"/>
  </head>

  <body bgcolor="white">
    <h1 class="title">Web Application Development</h1>
    <div class="toc"><ol><li><a href="#auto0">Code layout</a></li><li><a href="#auto1">Web application deployment</a></li><li><a href="#auto2">Understanding resource scripts (.rpy files)</a></li></ol></div>
    <div class="content">
<span/>

<h2>Code layout<a name="auto0"/></h2>

<p>The development of a Twisted Web application should be orthogonal to its
deployment.  This means is that if you are developing a web application, it
should be a resource with children, and internal links.  Some of the children
might use <a href="https://launchpad.net/nevow" shape="rect">Nevow</a>, some
might be resources manually using <code>.write</code>, and so on.  Regardless,
the code should be in a Python module, or package, <em>outside</em> the web
tree.</p>

<p>You will probably want to test your application as you develop it.  There are
many ways to test, including dropping an <code>.rpy</code> which looks
like:</p>

<pre class="python"><p class="py-linenumber">1
2
</p><span class="py-src-keyword">from</span> <span class="py-src-variable">mypackage</span> <span class="py-src-keyword">import</span> <span class="py-src-variable">toplevel</span>
<span class="py-src-variable">resource</span> = <span class="py-src-variable">toplevel</span>.<span class="py-src-variable">Resource</span>(<span class="py-src-variable">file</span>=<span class="py-src-string">&quot;foo/bar&quot;</span>, <span class="py-src-variable">color</span>=<span class="py-src-string">&quot;blue&quot;</span>)
</pre>

<p>into a directory, and then running:</p>

<pre class="shell" xml:space="preserve">
% twistd web --path=/directory
</pre>

<p>You can also write a Python script like:</p>

<pre class="python"><p class="py-linenumber">1
2
3
4
5
6
7
8
9
</p><span class="py-src-comment">#!/usr/bin/env python</span>

<span class="py-src-keyword">from</span> <span class="py-src-variable">twisted</span>.<span class="py-src-variable">web</span> <span class="py-src-keyword">import</span> <span class="py-src-variable">server</span>
<span class="py-src-keyword">from</span> <span class="py-src-variable">twisted</span>.<span class="py-src-variable">internet</span> <span class="py-src-keyword">import</span> <span class="py-src-variable">reactor</span>
<span class="py-src-keyword">from</span> <span class="py-src-variable">mypackage</span> <span class="py-src-keyword">import</span> <span class="py-src-variable">toplevel</span>

<span class="py-src-variable">reactor</span>.<span class="py-src-variable">listenTCP</span>(<span class="py-src-number">8080</span>,
    <span class="py-src-variable">server</span>.<span class="py-src-variable">Site</span>(<span class="py-src-variable">toplevel</span>.<span class="py-src-variable">Resource</span>(<span class="py-src-variable">file</span>=<span class="py-src-string">&quot;foo/bar&quot;</span>, <span class="py-src-variable">color</span>=<span class="py-src-string">&quot;blue&quot;</span>)))
<span class="py-src-variable">reactor</span>.<span class="py-src-variable">run</span>()
</pre>

<h2>Web application deployment<a name="auto1"/></h2>

<p>Which one of these development strategies you use is not terribly important,
since (and this is the important part) deployment is <em>orthogonal</em>.
Later, when you want users to actually <em>use</em> your code, you should worry
about what to do -- or rather, don't.  Users may have widely different needs.
Some may want to run your code in a different process, so they'll use
distributed web (<code class="API"><a href="http://twistedmatrix.com/documents/13.2.0/api/twisted.web.distrib.html" title="twisted.web.distrib">twisted.web.distrib</a></code>).  Some may be
using the <code>twisted-web</code> Debian package, and will drop in:</p>

<pre class="shell" xml:space="preserve">
% cat &gt; /etc/local.d/99addmypackage.py
from mypackage import toplevel
default.putChild(&quot;mypackage&quot;, toplevel.Resource(file=&quot;foo/bar&quot;, color=&quot;blue&quot;))
^D
</pre>

<p>If you want to be friendly to your users, you can supply many examples in
your package, like the above <code>.rpy</code> and the Debian-package drop-in.
But the <em>ultimate</em> friendliness is to write a useful resource which does
not have deployment assumptions built in.</p>

<h2>Understanding resource scripts (<code>.rpy</code> files)<a name="auto2"/></h2>

<p>Twisted Web is not PHP -- it has better tools for organizing code Python
modules and packages, so use them.  In PHP, the only tool for organizing code is
a web page, which leads to silly things like PHP pages full of functions that
other pages import, and so on.  If you were to write your code this way with
Twisted Web, you would do web development using many <code>.rpy</code> files,
all importing some Python module. This is a <em>bad idea</em> -- it mashes
deployment with development, and makes sure your users will be <em>tied</em> to
the file-system.</p>

<p>We have <code>.rpy</code>s because they are useful and necessary.
But using them incorrectly leads to horribly unmaintainable
applications.  The best way to ensure you are using them correctly is
to not use them at all, until you are on your <em>final</em>
deployment stages.  You should then find your <code>.rpy</code> files
will be less than 10 lines, because you will not <em>have</em> more
than 10 lines to write.</p>

</div>

    <p><a href="index.html">Index</a></p>
    <span class="version">Version: 13.2.0</span>
  </body>
</html>