Reputation: 589
I know that there are a lot of questions with this error but I am trying all of the tips and I am not having success yet.
I installed django and I want to introduce two images in my web map. I try everything and the images are not found yet.
I have a folder static inside my project and inside static I have a folder images with the images. I also tested with the folder images outside the static folder.
In my settings.py
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'gic\static')]
MEDIA_ROOT = os.path.join(BASE_DIR, 'images')
MEDIA_URL = '/images/'
and in index.html file
{% load static %}
<img src="{% static "coalmine_logo.png" %}" alt="Cinque Terre" width=350 height=120/>
and an error appears:
GET http://localhost:8000/static/coalmine_logo.png 404 (Not Found)
Upvotes: 0
Views: 6067
Reputation: 838
Since you images are within a subfolder of your static folder you need to add that folder name to the path. In your template it should look like this:
{% static 'images/coalmine_logo.png' %}
Edit:
The reason this wasn't working for the poster was because they had their static files they were trying to access in the directory that was specified in STATIC_ROOT
in their settings file. In development django does not look in the STATIC_ROOT
directory for statics files, it looks in the directories listed in the STATICFILES_DIRS
variable. This was fixed for the poster by moving their files into the directory that matched their line os.path.join(BASE_DIR,'gic\static')
Upvotes: 2