[Zope] RESPONSE.write(text) and RESPONSE.flush()

Paul Winkler pw_lists at slinkp.com
Tue May 11 21:22:21 EDT 2004


On Tue, May 11, 2004 at 05:31:08PM -0700, Joe Goldthwaite wrote:
> This works but not as well as I hoped.   There are so many jobs that the
> final result is off the bottom of the page so if the user doesn't scroll
> down, he can't see that its done.  I also wanted to display the data on a
> formatted HTML page but it looks like the write function encodes any html so
> that you can see it.  This effectively keeps me from producing any kind of
> formatted output.  Is there any way to get the write function to return my
> text to the browser unchanged?

It does so. But maybe your browser thinks the result is
plain text, not html.  Maybe this would help (before any
calls to RESPONSE.write):

RESPONSE.setHeader('Content-type', 'text/html')

Note that also when you are doing RESPONSE.write, you should
always first do RESPONSE.setHeader('Content-length', N)
where N is the size of the data you will write.
If you don't know this length, you can overestimate it -
in which case the browser status bar will never show the page as "done".
I've dealt with the latter problem by keeping track of how
may bytes I write, and padding the result at the end, like this:

RESPONSE.write(' ' * (N - written_so_far))

Hacky, but it works fine.

> I also had the great idea of redirecting to a "finished" page with the
> command;
> 
> RESPONSE.redirect("finished")
> 
> Where "finished" is just a simple html page that displays "done" with a link
> to return to the home page.  The only problem is that it doesn't work and I
> don't know why.  I also tried to return a formatted html page from my
> external method after it calls the Build function but it's ignored.  For
> some reason, if I call RESPONSE.write(), I can't return any other html to
> Zope.

That's normal. RESPONSE.write() is a low-level way of getting data
to the client, and should not be combined with the "normal"
techniques.

-- 

Paul Winkler
http://www.slinkp.com



More information about the Zope mailing list