Saving image problem in view

Firstly hope this is the correct Subchannel (this is view related). I’ll try to explain my issue and cut to the chase with the code, although I may need to expand my code submission to explain in better detail.

I’m working on an image object in a view, editing some metadata within it, then saving it. I am then accessing the image again with via it’s pk and assigning it to a new variable which is passed via context to the template. The image is displayed but instead of it being the ‘new image’ with changed metadata when i right-click save-as, it’s the ‘original’. But, when I open the ‘new image’ in a new window and save-as the data has changed.

So, saving image then accessing it again. All pretty straightforward. But the new_image isnt updating it’s changes in metadata until I open it in a new window…

image.save()
new_image = Uploaded_Image.objects.get(pk=image.pk) 
return render(request, "partials/test.html", {'image':image, 'new_image': new_image}

Then template

<img src="{{ new_image.image.url  }}" >

Ok, i have solved this, although I’m unsure if this is the best way to go about this. I had to open the file and directly render it from it’s path.

            new_image = Uploaded_Image.objects.get(pk=image.pk)  
            image_url = new_image.image.url
            image_path = os.path.join(settings.BASE_DIR, image_url.strip('/'))
            with open(image_path, 'rb') as file:
                new_image = file.read()

#new_image passed in context.

I then had to write a file to do the Base64 encoding for it to render in template.