[Fixed]-Django template img src not working

18👍

That happens because Django does not know the path to this image.
Make a folder named static/, and then a folder named images/ in your project root(where your settings.py file resides).

my_project/
    my_project/ 
        settings.py
        static/
           images/
             google.png

And then change it to:

<img src="{{STATIC_URL}}images/google.png" / >

More here.

26👍

In recent versions of django

<img src="{% static 'path/to/image.ext' %}"/>

10👍

You have got to add load static tag in the beginning of your Django template, best luck with below code.

{% load static %} 
<img src="{% static 'path/to/image.ext' %}"/>

Leave a comment