niloofar
niloofar

Reputation: 2334

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?

Upvotes: 0

Views: 6961

Answers (2)

Sagar
Sagar

Reputation: 21

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.

Upvotes: 0

E Rodriguez
E Rodriguez

Reputation: 323

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"/>

Upvotes: 7

Related Questions