[mod_python] mod_python article

Jorey Bump list at joreybump.com
Wed Nov 9 17:36:36 EST 2005


Graham Dumpleton wrote:
> A few comments of my own to expand on what Jorey as already
> pointed out.
> 
> Jorey Bump wrote ..
> 
>>1. Replace AddHandler with SetHandler in your example configuration.
> 
> Even if SetHandler is used, with the action specified in the form, the
> mod_python code would need to be saved as "python/index.py".

Natch. I don't recommend starting off with this in a tutorial, though, 
as it's an advanced topic. Well, it's pretty simple, actually, but not 
when compared to the notion of other index.* files (index.html, 
index.php, index.pl,...). Furthermore, it's not standardized across 
versions of mod_python still in use.

> If the name of the mod_python code file were "python/getmonth.py" then
> your action would need to be "python/getmonth.py/getMonth".

Or "python/getmonth/getMonth", when using SetHandler, requiring some 
further explanation of the differences between AddHandler & SetHandler...

> It isn't clear what the name of the mod_python code file is supposed to
> be, so anyone following the article may get confused.
> 
> One could still use AddHandler if it were corrected to:
> 
>   AddHandler mod_python.py

Corrected correction:

  AddHandler mod_python .py

But the context of the article suggests he wants SetHandler:

"This means that all files under the directory will be processed by the 
mod_python handler."

> If you want to not be able to use ".py" in the URL, then you have extra
> work to do to ensure that MultiViews matching in Apache is properly
> configured.

Or just use SetHandler, of course.

>>2. Provide the name of your published module.
> 
> Is this what I described further above as far as the name of the mod_python
> code file, or do you mean something else???

Yes. I was intentionally terse, to help emphasize the karmic 
implications of each point. Using SetHandler goes a long way towards 
fixing the article, but only if the published module is named index.py. 
As you suggest, it's better to use a different file name for 
demonstration purposes.

>>3. Use a return statement instead of req.write().
> 
> Thus you mod_python code becomes:
> 
>    import calendar
>    def getMonth(req,month):
>       req.content_type = 'text/plain'
>       req.write(calendar.month(2005, int(month),2,3))
>       return "\n"
> 
> or if returned as result:
> 
>   import calendar
>   def getMonth(req,month):
>       return calendar.month(2005, int(month),2,3)

The second example is best for an introduction to Publisher. I think a 
simple Publisher tutorial is possible without exploring all of the 
pitfalls in detail, but their existence should be noted.

Joshua, are you able to revise the article? I don't think a beginner 
could get mod_python.publisher working as described. I won't comment on 
the PSP part, as I don't use it. But, your overall presentation is quite 
nice, if you can fix the errors.




More information about the Mod_python mailing list