[mod_python] Try # 2: Mod_python.publisher behavior - sending .py file to browser - Still !

Geoff Skerrett geoff at teammsa.com
Sun May 7 13:51:45 EDT 2006


Graham Dumpleton wrote:
> 
> On 07/05/2006, at 5:24 PM, Geoff Skerrett wrote:
> 
>> I created a very simple program index.py program to help me 
>> understand the behavior.
>> It is as follows;
>>
>> ### Begin index.py
>>
>> def index(req):
>>     req.write("I am in index()")
>>     
>> def bar(req):
>>     req.write("I am in bar()")
> 
> Whoops. Quite obvious really. You must use:
> 
>   def index(req):
>     return "I am in index()"
>     
>   def bar(req):
>     return "I am in bar()"
> 
> When you you use req.write(), the headers are automatically flushed, 
> so the setting of req.content_type by mod_publisher after the 
> published function returns has no affect.
> 
> In other words, if you are going to use req.write(), you must set 
> req.content_type yourself.

Geoff,

Also, when you are using req.write() directly and not setting the
content_type, you are depending on the browser making a best guess. You were
getting different results because your browser was not consistent its guess.
The behaviour will differ on various browsers.

Jim

>From Geoff Skerrett;
Thank you Jim and Graham for you help on this.  It was of course the
solution and I am now in the right track.

Geoff.





More information about the Mod_python mailing list