On Fri, Apr 11, 2008 at 2:05 PM, Steve Holden <[EMAIL PROTECTED]> wrote:Then browse to the URL this program serves and you will see the image (assuming you are still sending the image/jpeg content type).Well, as I mentioned before, I am sending text/html because the page, likealmost all web pages, has a whole lot more content than just images. Or,perhaps you are suggesting I build my pages in frames, and have a frame forevery image. Unsightly!
(Oh my...!) Thanks to Helloween (the metal band) I was in the right mood to write a small example. Simple, bare, raw code: no fancy HTML, no templates, no web frameworks, using the embedded sqlite engine. It works with Python 2.5 out of the box. Each functional piece is in its own file, to emphasize the one-document-per-request rule. It is a photo album, one can upload pictures with title and description, and later see them one at a time.
How to run: Create a temporary folder. Create a cgi-bin subdirectory, and copy the four scripts there. In the parent directory, execute: python -m CGIHTTPServer Using your browser, go to http://localhost:8000/cgi-bin/album.py?init=1 (the init parameter is to create the database; you can omit it once it's done).
Note that there are TWO scripts involved when you want to display a picture: showpic.py returns the HTML page, containing tags like this:
<img src='getpic.py?id=%d' alt='%s'>" % (picid, cgi.escape(title)) (note the src attribute) and getpic.py returns the picture itself.Note also that this is just a demo; for a real web application I would choose one of the many existing frameworks; or WSGI, or mod_python, finally cgi. And my scripts have absolutely no check for errors at all, and the HTML is not even valid.
I hope you finally get the idea of how to serve dynamic content... -- Gabriel Genellina
upload.py
Description: Binary data
album.py
Description: Binary data
getpic.py
Description: Binary data
showpic.py
Description: Binary data
-- http://mail.python.org/mailman/listinfo/python-list