Is there any way of redirecting an image’s ‘request’ URL in Django views, to an Nginx server so that Django doesn’t have to serve the image itself? The background to my questions has to do with image tracking, which for obvious reasons requires a trip to Django.
If you’re storing this in a models.ImageField or models.FileField, I’d recommend using model_instance.image_field.url rather than attempting to generate the file_path, then having nginx serve all requests that are made to the MEDIA_URL as defined your settings.
When the recipient views the email, a request for the image is sent to Django views (assuming that viewing email images is allowed by the email client), whereupon the UUID is stripped and the image is served.
Maybe it’s my inexperience with Django, but I do not understand how using a model_instance.image_field.url would help. Could you perhaps give me an example in the context of my def track_image(request, key1, key2): code above?
Thanks again.
Your track_image view should take the parameters that you can look up the model instance. Then it should return a redirect response to the instance’s image file’s url.
This will require the client to do another round trip, but unless your media files are on the same machine the additional overhead compared to reading the images data in and then rendering it as a response should be insignificant.