[reportlab-users] Image in a Python page

David Frank david83 at sfsu.edu
Tue Jun 5 17:36:08 EDT 2007


Hello Tim and Andy,

Once again, I cannot be grateful enough for the help that I have got from
you guys and from the forum.

Thank you for enlightening me on this topic. This has been very very
interesting and very knowledgeable. I really appreciate your efforts.

Best Regards,

David Frank




David Frank wrote:

>

> It makes a lot of sense to me now. Thank you for the awesome reply.

> Just one last question (since this is getting way out of topic of

> reportlab).....so how would someone be able to put both the

> content-types in the same file (for pages that have both html as well

> as images)?


They are completely separate transactions. You send a response with the
HTML that has Content-Type: text/html. Part of that HTML will be an
<img> tag. That tag is just plain text that will be interpreted by the
browser. When the browser sees it, it will send another HTTP request to
the server asking for the URL in the <img> tag. The server will send
back a response with Content-Type: image/gif. One transaction, one
content-type.

This is something that many people don't realize. When you fetch a web
page with 50 images on it, the browser actually ends up sending 51
completely independent HTTP requests.

--
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.


> 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://two.pairlist.net/pipermail/reportlab-users/attachments/20070605/9e013a6e/attachment-0001.htm>


More information about the reportlab-users mailing list