Sophie

Sophie

distrib > Mandriva > 8.2 > i586 > media > contrib > by-pkgid > 12aef6395c3678c929b08cd723fc1673 > files > 61

mod_python-2.7.6-1mdk.i586.rpm

<!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">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="STYLESHEET" href="modpython.css">
<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">&nbsp;</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 -&gt; /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.6, documentation updated on August 04, 2001.</span>
</DIV>
<!--End of Navigation Panel-->

</BODY>
</HTML>