[mod_python] conditions for a 404

David Bear David.Bear at asu.edu
Thu May 25 17:28:40 EDT 2006


Thanks for the extensive comments and instructions. Further comments
below..

On Thu, May 25, 2006 at 02:55:25PM -0400, Jorey Bump wrote:
> David Bear wrote:
> >I have a file called tddb.py which contains
> >
> >"""
> >from mod_python import session
> >
> >def index(req):
> >  req.content_type = "text/plain"
> >  req.send_http_header()
> >  req.write("hello world")
> 
> These statements are unnecessary when using Publisher.
> 

okay. I was getting mixed up trying to read too much of the
documentation.

Here's an idea. I was looking for a way to use python to 'publish'
information through apache. I wasn't looking for a way to change
apache.

It seems modpython is more suited to changing apache that just
'pubilshing'. In order to understand how to use modpython to 'publish'
you really need to understand a LOT about the way apache 'publishes'
information. I looked at the publisher handler as a shortcut to
'publishing' the results of python functions, ie a way to make a
python namespace accessible via urls. (coming from doing zope this was
an easy paradigm to work from)

> >  keys = req.keys()
> 
> req has no keys method.
> 
> >  for k in keys:
> >    req.write("object name is %s " % k)
> >  req.write("done")
>

yes. I was poking around trying to see what methods were available on
the request object. I didn't see this documented in the web site..
(but then, I'm still trying to understand the meaning of a lot at
modpython.org)

> 
> def index(req):
>     return "\n".join(["object name is %s " % (i,) for i in dir(req)])
> 
> It is very different from other web application languages, so forget 
> everything you know about PHP or CGI for now, as they will only create 
> false expectations. Pretend that you are learning web programming from 
> scratch, and you may eventually find that it makes a lot of sense. There 
> are caveats, however, and mod_python itself is a bit of a moving target 
> while it is evolving. Be sure to read the documentation aimed at your 
> specific version, and always report your apache/mod_python versions when 
> asking for help.

yes -- this is becoming more true for me. I attempted a reformulation
of my original script. It still generates the 404 error.
==================================
from mod_python import session

page1 = '''
<html>
 <head>
  <title>page 1 </title>
 </head>
 <body>
  this is page 1 boo
 </body>
</html> 
'''

def index(req):
  return page1

def info(req):
  res = []
  thereq = dir(req)
  for i in thereq:
    res.append(i)
  return("%s " % res)
===============================

> 
> I recommend that beginners master Publisher and ignore PSP for the 
> timebeing. That will help you get in the right frame of mind, and 
> Publisher is simple (yet powerful) enough to study when/if you decide to 
> write your own handler.

this is good advice. However, the best example code available at
modpython.org is at  http://modpython.org/examples/ using publisher
and psp.  I would love more example code to learn from. But it seem
rather scarce. There are no books at amazon about modpython. googling
for it almost always yields pages that use addons like vampire,
django, or other templating systems.

Any good sources for information on publisher?

-- 
David Bear
phone: 	480-965-8257
fax: 	480-965-9189
College of Public Programs/ASU
Wilson Hall 232
Tempe, AZ 85287-0803
 "Beware the IP portfolio, everyone will be suspect of trespassing"


More information about the Mod_python mailing list