[mod_python] Handler return value is rendered in output

Jim Gallacher jpg at jgassociates.ca
Tue Feb 13 22:24:49 EST 2007


Hi David,

It looks like you are using the publisher handler. It works at a higher 
level than a simple mod_python hanlder and looks after the apache return 
value for you. Anything returned by the published method will be sent to 
the client. For example

def comment(req):
     return 'Hello world'

would return "Hello world" to the browser. This is why you are seeing 
the extra 0 appended to your output.

Jim

David Cooper wrote:
> Hi Guys,
> 
>  
> 
> Firstly thanks for reading - I'm a complete newb to mod_python, having
> installed it only yesterday.
> 
>  
> 
> I have had some success with the provided examples, however I've got
> some troubles with the return value of my handlers being rendered in the
> output. The following code renders a 0 on the page, which is not what I
> expected? 
> 
>  
> 
> --- form.html ---
> 
>  
> 
>   <form action="comment.py/comment" method="POST" >
> 
>       Comment: <textarea name="comment" rows=4 cols=20></textarea><input
> type="submit"><br>
> 
>   </form>
> 
>  
> 
> --- comment.py ---
> 
>  
> 
> from mod_python import apache
> 
> def comment(req, comment):
> 
>       return apache.OK
> 
>  
> 
> Also, if I return apache.HTTP_NOT_FOUND then I just get a page with 404
> rendered at the top. 
> 
>  
> 
> Question: Why is my return value being interpreted as text to be
> rendered, rather than the signal to the mod_python framework whether
> everything's ok or not?
> 
>  
> 
> Thanks for any assistance!
> 
>  
> 
> Cheers, Dave.
> 
>  
> 
> 
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python



More information about the Mod_python mailing list