[Zope-dev] Writing results directly back to browser

David S. Harrison dsh@magma-da.com
Thu, 11 Nov 1999 18:57:13 -0800


Pavlos is correct.  What I didn't realize is that Zope treats the return
value from an external method as the actual content that will be returned
by the server (not the name of the content).  As long as my routine can
write the image into a Python string, it is easy to return that data
correctly for use in DTML.  The only trick is to make sure the content
type is set appropriately:

def GenerateImage(self, RESPONSE):
  # Image bits is a string containing the bytes of the image.
  imageBits = computeImage()
  RESPONSE.setHeader('content-type', 'image/png')
  return imageBits

In the DTML, I can use a simple image tag to get access
to this image:

<!--#var standard_html_header-->
<h2><!--#var title_or_id--></h2>
<p>
This is the <!--#var id--> Document.  Below is a computed image:
<IMG SRC="GenerateImage">
</p>
<!--#var standard_html_footer-->

All in all, it looks like this is easier than I expected.  I am
certainly glad I don't have to worry about writing the images to
disk.  Figuring out when those files expire is always a nightmare.

				David S. Harrison
				(dsh@magma-da.com)

Pavlos Christoforou wrote:
> > >
> > > def gen_im(self):
> > >         imag=<code to generate image on the fly>
> > >         return imag
> > >
>