Django template img src not working

user1680859 picture user1680859 · Sep 18, 2012 · Viewed 60k times · Source

I want to print an image by using a img src tag in a Django template file "base.html":

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang="en">
<head>
    <title>Foto</title>
</head>
<body>
    <h1>My helpful timestamp site</h1>
    <img src="google.png" / >
    <hr>
    <p>Made by ... </p>
</body>
</html>

In views.py I define:

def hello(request):
    return render_to_response('base.html')

But the image does not show up in the browser. If I open it as a simple html file, it shows up in the browser.

Answer

chandan picture chandan · Mar 5, 2016

In recent versions of django

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