0

Django is not loading my static files. I'm trying to load an image from the static folder, but it doesn't work.

file.html

<body>

      {% load static %}
      <img src="{% static "products/logo.jpg" %}" alt="My image">
</body>

structure

app
|_______products
       |_________templates
                 |_________file.html
       |_________models.py
       |_________ ...

|______static
       |_________products
                 |_________logo.jpg

settings

...
INSTALLED_APPS = [
    ...
    'django.contrib.staticfiles',
    ...
]

...

STATIC_URL = '/static/'
alpha
  • 511
  • 8
  • 15
  • Does this answer your question? [Django Static files 404](https://stackoverflow.com/questions/12809416/django-static-files-404) – Jorge Luis Jun 07 '20 at 22:35

2 Answers2

1

You need to put this in your settings.py file:

STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]
MeL
  • 1,269
  • 3
  • 12
  • 30
0
<!DOCTYPE html>
<html>   
<head>
{% load static %}
</head>
<body>
<img src="{% static "products/logo.jpg" %}" alt="My image">
</body>
</html>

settings:

STATIC_DIR = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'
STATICFILES_DIRS = [STATIC_DIR, ]
Houda
  • 671
  • 6
  • 16