0

I'm having some trouble displaying images in a website I'm building. I am following the instructions in the Django static files documentation. To wit, I have:

  1. Verified that my settings.py file contains STATIC_URL = 'static/'
  2. Added the equivalent of the following code to my template:
    {% load static %}
    <img src="{% static 'my_app/example.jpg' %}" alt="My image">
  1. Stored my images in `my_app/static/my_app/

I get no error when I navigate to the relevant page. Just an empty div where the image should be.

It seems like in the past, this problem has been solved by using render() (example). However, I'm using Django 4.x, as well the render() function.

Why aren't my images showing up?

spheroidic
  • 199
  • 7

1 Answers1

0

There is one more requirement, and that is adding the static url settings to our urlpatterns:

from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
    # ... the rest of your URLconf goes here ...
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

This is from the section "Serving static files during development" from that same document.

spheroidic
  • 199
  • 7