On Wed, Jun 13, 2007 at 12:29:10AM -0700, MartinWinkler wrote:
> 
> > I don't recall hearing a good argument for *not* delivering the images
> > dynamically, without saving them to disk.  Why not do it that way?
> 
> Since I do not want the developer to change anything in urls.py or add
> some middleware or cookies - what would be the URL of this dynamically
> generated image?

Well, you would have to have a line added to urls.py, that's for sure.  If you
really want to avoid that, I suppose you have to save the images to disk.

I've found that writing things to disk from web applications often carries
higher maintenance penalties than adding a line to urls.py would; that's
obviously an implementation trade off, though, so I suppose it's not
unreasonable that you would make that trade off differently than I would.

> And how would it be possible to join this image with the form that is
> being sent back?

There are a variety of ways to maintain state between multiple connections, even
without cookies (although that is the most straight-forward and reliable way).
For this sort of thing, you could probably generate an image, store it
temporarily in memory or the database, generate an ASCII hash value of the image
and use that as the filename (which you write to the page), and send the correct
image based on the hash value encoded in the client's request for the image
file.

Alternatively, you could roll the dice and try to sort-of-unique-ly identify
users by IP address & hostname...

It would be a heck of a lot easier to use a session variable, though.  What's
the reason not to?

Now that I think about it, you don't even need to generate the image at
form-generation time, depending on how the image generation works.  You could
just generate the string to be depicted by the image, and hash that.  Then,
generate the image when it is actually requested.  This would save you from
storing the image at all; you would only have to store the string (and maybe the
hash, too, to avoid calculating it more than once).

-Forest

Attachment: signature.asc
Description: Digital signature

Reply via email to