[reportlab-users] Image in a Python page

Andy Robinson andy at reportlab.com
Tue Jun 5 16:07:01 EDT 2007


On 05/06/07, David Frank <david83 at sfsu.edu> wrote:

>

> Tim, I still dont get this Content-type thing. I tried what you advised, but

> Python still ends up printing the line, as is, on the page. So, I put

> 'Content-type: image/gif\n' before 'Content-type: text/html\n' and the page

> gives an error. I guess it's something to do with Apache and its

> configuration. I think I should start studying it more deeply.


You would only output "Content-type: image/gif" if you intended to
generate the GIF and "print" its content straight to the output,
without saving it to disk. This is very handy if making a dynamic
chart as you can code web pages with tags like this...

<img src="/cgi-bin/piechart.cgi?data=10,20,30">

However, in your case you were explicitly saving the chart to disk,
and returning HTML with a link to the chart. So your content-type
would be HTML and you were doing the right thing.

It's worth practicing this stuff though. The HTTP protocol involves
writing headers (one of which says what kind of content is coming up),
then a blank line, then the content. Print statements or newlines in
the wrong place can result in the client seeing an 'Internal server
error'.

- Andy


More information about the reportlab-users mailing list