[mod_python] How do I serve dynamic images?

Sean Davis sdavis2 at mail.nih.gov
Wed Feb 27 14:53:46 EST 2008


On Wed, Feb 27, 2008 at 2:25 PM, happybrowndog
<happybrowndog at hotmail.com> wrote:
> I've searched the web but have only seen code to serve dynamically
>  generated images in the following way:
>         buff = StringIO.StringIO()
>         img.save(buff,...)
>         req.write(buff.getvalue())
>  and setting the appropriate html headers.  This is fine if I want to
>  serve the image in its own page.
>
>  But how do I serve dynamically generated images inside an <img> tag?

You simply have the URL of the image generation code in the <img> tag.

<img src='http://myserver.com/mygraphmaker.py' />

Of course, you might need to include a query parameter in there if the
image code needs some parameters....  You could also make javascript
calls to do the same thing.

There is not a way to print the buffer directly to the page.

Sean


More information about the Mod_python mailing list