How to correctly output an image to the template in Django?

The image of the page is not displayed. Most likely I am incorrectly specifying the path to the image file. Please tell me what I should fix in my code?

Code in the template

<main>
  {% block content %}
  <p>
    <img src="../outputs/imgoutputs/14.jpg" width="189" height="255" alt="lorem">
  </p>
  {% endblock %}
</main>

Approximate project structure:

project -generate(app) -views.py -outputs -imgoutputs -14.jpg -templates -thankyou.html

Help me please to correctly specify the path to the image.

For your image to show up the official way is to use the static tag, so something like that :

<img src="{% static 'outputs/imgoutputs/14.jpg' %}" alt="My image"/>

This suppose that your image is inside static/outputs/imgoutputs/14.jpg

Don't forget to add {% load static %}

You do not need the static folder, Django knows how to find your image.

Back to Top