Reem Abdulrhman
Reem Abdulrhman

Reputation: 27

how can I refresh image in Django HTML

I'm trying to refresh the image after pressing the button I include the image in static files.. im using Django with HTML py

Upvotes: 0

Views: 1001

Answers (2)

Felix Eklöf
Felix Eklöf

Reputation: 3720

If you're looking to fetch the image again without reloading the page you can do something like this.

<img id="pic" src="{% static 'images/graph.png' %}" onclick="reloadimg()" style="display:none;" />
<script>
    function reloadimg(){
        var src = "{% static 'images/graph.png' %}";
        imageObject = document.getElementById("pic");
        imageObject.style.display = 'inline-block';
        imageObject.src = src;  
    }
</script>

Upvotes: 4

In django by default if server is running on debug mode, it should refresh,

if it is not refreshing, try running command python manage.py collectstatic and do hard refresh of page by Ctrl + shift + R

Upvotes: 1

Related Questions