Karan Yogi
Karan Yogi

Reputation: 91

Cannot load static files in django

I added the following lines in my settings.py file:

STATIC_URL = '/static/'
STATICFILES_DIR = [
   os.path.join(BASE_DIR,"static"),
]
STATIC_ROOT = os.path.join(BASE_DIR,"static")

Then I edited my HTML file to use {% load static %} and <img src="{% static 'static/myapp/images/ABC.png' %}" alt="">, but still I am not able to see the ABC.png pic on my webpage. Can someone please help?


Screenshots of .py files: Screenshots of .py files

Upvotes: 0

Views: 132

Answers (1)

Yasiel Cabrera
Yasiel Cabrera

Reputation: 598

The issus is that you are incorrectly requesting the asset, use {% static 'myapp/images/ABC.png' %} instead. I suppose that you have the following structure in your app:

myapp
   static
      myapp
         images
            ABC.png
   templetes
   views.py
   ...

As you can see, is not necessary to add the name of your statics directory. The path is relative to the static folder of any of your apps in your project.

Upvotes: 1

Related Questions