'django set image src path

I want to set an image as a submit button form:

<form action="/final" method="post">{% csrf_token %}
    <input type="hidden" name="title" value="niloofar">
    <input type="image" name="submit" src="cat.jpg">
</form>

The image is in the template directory and the image is not shown. How should I manage it with STATIC_URL = '/static/'?

Should I make a directory called static and put the image there?

And how the form should be changed?



Solution 1:[1]

You need to properly configure your static files. More info can be found in Django docs

Additionally, make sure you are writing the correct path the image, as shown in the docs:

{% load staticfiles %}
<img src="{% static "my_app/myexample.jpg" %}" alt="My image"/>

Solution 2:[2]

Now some changes are there to be noted. You should not load your static files with

{% load staticfiles %}

Instead you should write

{% load static%}

And in source (denoted as src), you should give path of image file from static folder located in your directory. Not from the local resources.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 E Rodriguez
Solution 2 Sagar