django media files only available after reloading page (DAPHNE, Debug = True)

29 Views Asked by At
  1. I have a view that save an image in my media file (im.save('media/test.png')
  2. In my template, I try to display it (img src="/media/test.png")

The image will only appear after I reload the page How can I display the image whitout reloading the page please ?

1

There are 1 best solutions below

0
Sahil On

I see your code and image path perfectly. but implement some extra functionality.

You need to add JavaScript, when you upload a new image that time without page reloading you see your uploaded image.

HTML

<img id="badge" src="$cms_url/imaging/badge.php?badge=$mygroup['badge']; ?>">/imaging/badge.php?badge=<?php echo $mygroup['badge']; ?>" />
document.getElementById("badge").src="new image src here";

Js query

 $("#badge").attr("src", "new image src here");

for more information Click on this link