I'm focusing on a django project that delivers an API to create pictures of images, and also the fundamental logic is much like the next:

  1. once the source image URL comes the very first time, the django would perform some kind of image manipulation, and return the thumbnail image

  2. once the same image URL comes again, django would simply serve the prior thumbnail image (saved as static media) again.

essentially, situation 2 happened much frequently than situation 1. Now I made use of django for everyone the pictures constantly, that we believe is really a bad practice.

I question if you can perform a better method of image serving for situation 2? For instance, can there be some kind of method to request django to transmit proxy demands to apache and request apache for everyone the file?

I understand I possibly could use HTTP redirect to achieve that, but that appears to create an excessive amount of redirect demands around the client side (one HTML page would contain lots of links for this API).

thx.

The easiest solution of the top my mind is always to make use of an Apache rewrite rule having a condition.

RewriteCond %(REQUEST_URI) ^media
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule #Some rewrite rule to redirect from '/media/filename' to '/image_generator/filename'

This essentially just inspections to determine if the file is available in media directory, and when it does not it transmits the consumer towards the image generator, which could then generate and save the file to /media where it may be found for the following request.

NB: I have never really attempted this kind of redirection with Django, so it should take a degree of of fine-tuning..

For instance, can there be some kind of method to request django to transmit proxy demands to apache and request apache for everyone the file?

You've that exactly backwards.

Browse the Django deployment guide. https://docs.djangoproject.com/en/1.3/howto/deployment/modwsgi/#serving-files

Apache ought to be serving all static files (images, for instance) constantly. Always.

Django should not, ever serve a picture file (or perhaps a .css or .js or anything apart from .html).

See later thing about this section in documentation:

http://code.google.com/p/modwsgi/wiki/ConfigurationGuidelines#The_Apache_Alias_Directive

Using Alias/AddHandler/mod_rewrite enables Django to overlay static files in filesystem. Quite simply, static files take priority.