Hi, Jim:

Jim Gallacher wrote:
The following page has been changed by JoreyBump:
http://wiki.apache.org/mod_python/MostMinimalRequestHandler

------------------------------------------------------------------------------ Let's begin at the beginning. Here is the most minimal request handler possible:
  + {{{
    def handler(req):
        return 0
+ }}}

This is my first use of moinmoin, so I saved more frequently than necessary. I've already improved the page and discovered the preview button. :)

FYI, you can get python syntax highlighting by starting your code block with {{{#!python

Thanks for the tip.

Also I would avoid using "return 0". I know you want it to be the most minimal handler possible, but I think it's better to encourage good coding habits by using "return apache.OK". It will then be more logical when users move on to more sophisticated handlers, perhaps in other phases, where the handler may be returning something other than 0.

I've explained this in the final draft, and moved on to using apache.OK in the next example. This handler is obviously meant to do nothing, but to the uninitiated, the mod_python voodoo is quite thick. We take it for granted, but I think a novice will appreciate that the return code should be an integer (after all, that's what the debugger complains about if there's a related error).

One of the things we're up against is that I suspect a good chunk of our audience has no Python experience whatsoever, and they come to mod_python investigating alternatives to other web application development languages, like PHP. We can't assume they'll have many Python (or Apache) skills at all, so we should take the opportunity to ease them into basic concepts upfront (without dumbing it down, of course).

You could argue that it would be silly for a novice to start out by writing a custom handler, but the mailing list indicates that it happens all of the time.


Reply via email to