[reportlab-users] Image in a Python page
David Frank
david83 at sfsu.edu
Tue Jun 5 14:51:26 EDT 2007
Hi Tim,
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)?
Thanks,
David Frank
> 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.
It's actually part of the HTTP protocol. This is off-topic for this
list, but I cannot stop myself from answering technical questions...
The response that goes from a web server to a browser consists of two
parts: the HTTP part, and the body. It is very much like an e-mail
message. The HTTP part is a set of email-like headers that describe the
body. That ends with a blank line. Everything else is the body of the
response. You cannot tell anything about what is in the body without
looking at the headers, and especially at the "Content-Type" header. If
the Content-Type header says "text/html", then the body will be HTML to
be rendered by the browser. You can send the exact same HTML but change
the Content-Type header to "text/plain", and the browser will show the
HTML as plain text.
There are a lot of valid Content-Types that can be sent. GIF images get
sent as image/gif. In that case, the data that follows the blank line
would be binary GIF data.
Once you have set a Content-Type, it is set for the rest of the
response. You can't change it, because the browser stops looking for
headers when it sees that blank line. If you include a Content-Type
line in the middle of your HTML, the browser will see it as HTML data,
just as if I put another "Subject:" line in the middle of an email.
--
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.
_______________________________________________
reportlab-users mailing list
reportlab-users at reportlab.com
http://two.pairlist.net/mailman/listinfo/reportlab-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://two.pairlist.net/pipermail/reportlab-users/attachments/20070605/2786064c/attachment.htm>
More information about the reportlab-users
mailing list