/usr/share/doc/libapache2-mod-python-doc/doc-html/tut-pub.html is in libapache2-mod-python-doc 3.3.1-11ubuntu2.
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 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 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<link rel="STYLESHEET" href="modpython.css" type='text/css' />
<link rel="first" href="modpython.html" title='Mod_python Manual' />
<link rel='contents' href='contents.html' title="Contents" />
<link rel='index' href='genindex.html' title='Index' />
<link rel='last' href='about.html' title='About this document...' />
<link rel='help' href='about.html' title='About this document...' />
<link rel="next" href="tut-overview.html" />
<link rel="prev" href="tutorial.html" />
<link rel="parent" href="tutorial.html" />
<link rel="next" href="tut-overview.html" />
<meta name='aesop' content='information' />
<title>3.1 A Quick Start with the Publisher Handler</title>
</head>
<body>
<DIV CLASS="navigation">
<div id='top-navigation-panel' xml:id='top-navigation-panel'>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="3. Tutorial"
href="tutorial.html"><img src='previous.png'
border='0' height='32' alt='Previous Page' width='32' /></A></td>
<td class='online-navigation'><a rel="parent" title="3. Tutorial"
href="tutorial.html"><img src='up.png'
border='0' height='32' alt='Up One Level' width='32' /></A></td>
<td class='online-navigation'><a rel="next" title="3.2 Quick Overview of"
href="tut-overview.html"><img src='next.png'
border='0' height='32' alt='Next Page' width='32' /></A></td>
<td align="center" width="100%">Mod_python Manual</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
href="contents.html"><img src='contents.png'
border='0' height='32' alt='Contents' width='32' /></A></td>
<td class='online-navigation'><img src='blank.png'
border='0' height='32' alt='' width='32' /></td>
<td class='online-navigation'><a rel="index" title="Index"
href="genindex.html"><img src='index.png'
border='0' height='32' alt='Index' width='32' /></A></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="tutorial.html">3. Tutorial</A>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="tutorial.html">3. Tutorial</A>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="tut-overview.html">3.2 Quick Overview of</A>
</div>
<hr /></div>
</DIV>
<!--End of Navigation Panel-->
<H1><A NAME="SECTION005100000000000000000"></A><A NAME="tut-pub"></A>
<BR>
3.1 A Quick Start with the Publisher Handler
</H1>
<P>
This section provides a quick overview of the Publisher handler for
those who would like to get started without getting into too much
detail. A more thorough explanation of how mod_python handlers work
and what a handler actually is follows on in the later sections of the
tutorial.
<P>
The <code>publisher</code> handler is provided as one of the standard
mod_python handlers. To get the publisher handler working, you will
need the following lines in your config:
<P>
<div class="verbatim"><pre>
AddHandler mod_python .py
PythonHandler mod_python.publisher
PythonDebug On
</pre></div>
<P>
The following example will demonstrate a simple feedback form. The
form will ask for the name, e-mail address and a comment and construct
an e-mail to the webmaster using the information submitted by the
user. This simple application consists of two files:
<span class="file">form.html</span> - the form to collect the data, and
<span class="file">form.py</span> - the target of the form's action.
<P>
Here is the html for the form:
<P>
<div class="verbatim"><pre>
<html>
Please provide feedback below:
<p>
<form action="form.py/email" method="POST">
Name: <input type="text" name="name"><br>
Email: <input type="text" name="email"><br>
Comment: <textarea name="comment" rows=4 cols=20></textarea><br>
<input type="submit">
</form>
</html>
</pre></div>
<P>
Note the <code>action</code> element of the <code><form></code> tag points to
<code>form.py/email</code>. We are going to create a file called
<span class="file">form.py</span>, like this:
<P>
<div class="verbatim"><pre>
import smtplib
WEBMASTER = "webmaster" # webmaster e-mail
SMTP_SERVER = "localhost" # your SMTP server
def email(req, name, email, comment):
# make sure the user provided all the parameters
if not (name and email and comment):
return "A required parameter is missing, \
please go back and correct the error"
# create the message text
msg = """\
From: %s
Subject: feedback
To: %s
I have the following comment:
%s
Thank You,
%s
""" % (email, WEBMASTER, comment, name)
# send it out
conn = smtplib.SMTP(SMTP_SERVER)
conn.sendmail(email, [WEBMASTER], msg)
conn.quit()
# provide feedback to the user
s = """\
<html>
Dear %s,<br>
Thank You for your kind comments, we
will get back to you shortly.
</html>""" % name
return s
</pre></div>
<P>
When the user clicks the Submit button, the publisher handler will
load the <tt class="function">email</tt> function in the <tt class="module">form</tt> module,
passing it the form fields as keyword arguments. It will also pass the
request object as <code>req</code>.
<P>
Note that you do not have to have <code>req</code> as one of the arguments
if you do not need it. The publisher handler is smart enough to pass
your function only those arguments that it will accept.
<P>
The data is sent back to the browser via the return value of the
function.
<P>
Even though the Publisher handler simplifies mod_python programming a
great deal, all the power of mod_python is still available to this
program, since it has access to the request object. You can do all the
same things you can do with a ``native'' mod_python handler, e.g. set
custom headers via <code>req.headers_out</code>, return errors by raising
<tt class="exception">apache.SERVER_ERROR</tt> exceptions, write or read directly to
and from the client via <tt class="method">req.write()</tt> and <tt class="method">req.read()</tt>,
etc.
<P>
Read Section <A href="hand-pub.html#hand-pub">7.1</A> <em class="citetitle"><a
href="hand-pub.html"
title="Publisher Handler"
>Publisher Handler</a></em>
for more information on the publisher handler.
<P>
<DIV CLASS="navigation">
<div class='online-navigation'>
<p></p><hr />
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="3. Tutorial"
href="tutorial.html"><img src='previous.png'
border='0' height='32' alt='Previous Page' width='32' /></A></td>
<td class='online-navigation'><a rel="parent" title="3. Tutorial"
href="tutorial.html"><img src='up.png'
border='0' height='32' alt='Up One Level' width='32' /></A></td>
<td class='online-navigation'><a rel="next" title="3.2 Quick Overview of"
href="tut-overview.html"><img src='next.png'
border='0' height='32' alt='Next Page' width='32' /></A></td>
<td align="center" width="100%">Mod_python Manual</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
href="contents.html"><img src='contents.png'
border='0' height='32' alt='Contents' width='32' /></A></td>
<td class='online-navigation'><img src='blank.png'
border='0' height='32' alt='' width='32' /></td>
<td class='online-navigation'><a rel="index" title="Index"
href="genindex.html"><img src='index.png'
border='0' height='32' alt='Index' width='32' /></A></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="tutorial.html">3. Tutorial</A>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="tutorial.html">3. Tutorial</A>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="tut-overview.html">3.2 Quick Overview of</A>
</div>
</div>
<hr />
<span class="release-info">Release 3.3.1, documentation updated on January 29, 2007.</span>
</DIV>
<!--End of Navigation Panel-->
</BODY>
</HTML>
|