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 231 232 233
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>6.4 ZHandler</title>
<META NAME="description" CONTENT="6.4 ZHandler">
<META NAME="keywords" CONTENT="modpython">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<link rel="STYLESHEET" href="modpython.css">
<link rel="first" href="modpython.html">
<link rel="contents" href="contents.html" title="Contents">
<link rel="index" href="genindex.html" title="Index">
<LINK REL="previous" href="hand-httpdapy.html">
<LINK REL="up" href="handlers.html">
<LINK REL="next" href="app-wininst.html">
</head>
<body>
<DIV CLASS="navigation">
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="hand-httpdapy.html"><img src="icons/previous.gif"
border="0" height="32"
alt="Previous Page" width="32"></A></td>
<td><A href="handlers.html"><img src="icons/up.gif"
border="0" height="32"
alt="Up One Level" width="32"></A></td>
<td><A href="app-wininst.html"><img src="icons/next.gif"
border="0" height="32"
alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Mod_python Manual</td>
<td><A href="contents.html"><img src="icons/contents.gif"
border="0" height="32"
alt="Contents" width="32"></A></td>
<td><img src="icons/blank.gif"
border="0" height="32"
alt="" width="32"></td>
<td><A href="genindex.html"><img src="icons/index.gif"
border="0" height="32"
alt="Index" width="32"></A></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" href="hand-httpdapy.html">6.3 Httpdapy handler</A>
<b class="navlabel">Up:</b> <a class="sectref" href="handlers.html">6. Standard Handlers</A>
<b class="navlabel">Next:</b> <a class="sectref" href="app-wininst.html">A. Windows Installation</A>
<br><hr>
</DIV>
<!--End of Navigation Panel-->
<H1><A NAME="SECTION008400000000000000000"> </A>
<BR>
6.4 ZHandler
</H1>
<P>
<b>NOTE:</b> This handler is being phased out in favor of the
<em class="citetitle"><a
href="hand-pub.html"
title="Publisher"
>Publisher</a></em> handler described in
Section <A href="hand-pub.html#hand-pub">6.1</A>.
<P>
This handler allows one to use the Z Object Publisher (formerly Bobo)
with mod_python. This gives you the power of Zope Object Publishing
along with the speed of mod_python. It doesn't get any better than
this!
<P>
WHAT IS ZPublisher?
<P>
ZPublisher is a component of Zope. While I don't profess at Zope
itself as it seems to be designed for different type of users than me,
I do think that the ZPublisher provides an ingeniously simple way of
writing WWW applications in Python.
<P>
A quick example do demonstrate the power of ZPublisher.
<P>
Suppose you had a file called zhello.py like this:
<P>
<dl><dd><pre class="verbatim">
"""A simple Bobo application"""
def sayHello( name = "World" ):
""" Sais Hello (this comment is required)"""
return "Hello %s!" % name
</pre></dl>
<P>
Notice it has one method defined in it. Through ZPublisher, that
method can be invoked through the web via a URL similar to this:
<P>
http://www.domain.tld/site/zhello/sayHello and
<BR>
http://www.domain.tld/site/zhello/sayHello?name=Joe
<P>
Note how the query keyword "name" converted to a keyword argument to
the function.
<P>
If the above didn't "click" for you, go read the ZPublisher
documentation at
http://classic.zope.org:8080/Documentation/Reference/ObjectPublishingIntro
for a more in-depth explanation.
<P>
QUICK START
<P>
<OL>
<LI>Download and install Zope.
<P>
</LI>
<LI>Don't start it. You're only interested in ZPublisher, and in order for
it to work, Zope doesn't need to be running.
<P>
</LI>
<LI>Pick a www directory where you want to use ZPublisher. For our purposes
let's imagine it is accessible via http://www.domain.tld/site.
<P>
</LI>
<LI>Make sure that the FollowSymLinks option is on for this directory
in httpd.conf.
<P>
</LI>
<LI>Make a symlink in this directory to the ZPublisher directory:
<dl><dd><pre class="verbatim">
cd site
ln -s /usr/local/src/Zope-2.1.0-src/lib/python/ZPublisher .
</pre></dl>
<P>
</LI>
<LI>Verify that it is correct:
<dl><dd><pre class="verbatim">
ls -l
lrwxr-xr-x 1 uid group 53 Dec 13 12:15 ZPublisher -> /usr/local/src/Zope-2.1.0-src/lib/python/ZPublisher
</pre></dl>
<P>
</LI>
<LI>Create an <span class="file">.htaccess</span> file with this in it:
<P>
<dl><dd><pre class="verbatim">
SetHandler python-program
PythonHandler mod_python.zhandler
PythonDebug
</pre></dl>
<P>
</LI>
<LI>Create an above mentioned zhello.py file.
<P>
</LI>
<LI>Look at http://www.domain.tld/site/zhello/sayHello?name=Joe
<P>
</LI>
</OL>
<P>
Noteworthy:
<P>
This module automatically reloads modules just like any other
mod_python module. But modules that are imported by your code will not
get reloaded. There are ways around having to restart the server for
script changes to take effect. For example, let's say you have a
module called mycustomlib.py and you have a module that imports it. If
you make a changes to mycustomlib.py, you can force the changes to
take effect by requesting http://www.domain.tld/site/mycustomlib/.
You will get a server error, but mycustomelib should get reloaded.
<P>
P.S.: ZPublisher is not Zope, but only part of it. As of right now, as
far as I know, Zope will not work with mod_python. This is because of
locking issues. Older versions of Zope had no locking, so different
children of apache would corrupt the database by trying to access it
at the same time. Starting with version 2 Zope does have locking,
however, it seems that the first child locks the database without ever
releasing it and after that no other process can access it.
<P>
If this is incorrect, and you can manage to get Zope to work without
problems, please send me an e-mail and I will correct this
documentation.
<DIV CLASS="navigation">
<p><hr>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="hand-httpdapy.html"><img src="icons/previous.gif"
border="0" height="32"
alt="Previous Page" width="32"></A></td>
<td><A href="handlers.html"><img src="icons/up.gif"
border="0" height="32"
alt="Up One Level" width="32"></A></td>
<td><A href="app-wininst.html"><img src="icons/next.gif"
border="0" height="32"
alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Mod_python Manual</td>
<td><A href="contents.html"><img src="icons/contents.gif"
border="0" height="32"
alt="Contents" width="32"></A></td>
<td><img src="icons/blank.gif"
border="0" height="32"
alt="" width="32"></td>
<td><A href="genindex.html"><img src="icons/index.gif"
border="0" height="32"
alt="Index" width="32"></A></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" href="hand-httpdapy.html">6.3 Httpdapy handler</A>
<b class="navlabel">Up:</b> <a class="sectref" href="handlers.html">6. Standard Handlers</A>
<b class="navlabel">Next:</b> <a class="sectref" href="app-wininst.html">A. Windows Installation</A>
<hr>
<span class="release-info">Release 2.7.10, documentation updated on December 07, 2003.</span>
</DIV>
<!--End of Navigation Panel-->
</BODY>
</HTML>
|