[reportlab-users] Image in a Python page

Tim Roberts timr at probo.com
Tue Jun 5 13:12:12 EDT 2007


David Frank 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.


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.



More information about the reportlab-users mailing list