Mark Kennedy
Mark Kennedy

Reputation: 180

Django: Static Image Not Loading

I'm having issues getting an image to load on my Django web application. I have used the online documentation and tried peoples suggestions that I found on Stackoverflow but I am still not having any luck getting it to load. Here is what I have:

Settings.py:

STATIC_DIR =  os.path.join(BASE_DIR,'static')

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

STATIC_URL = '/static/'
STATIC_ROOT = [STATIC_DIR,]

Urls.py:

from django.urls import path
from dir_app import views
from django.conf import settings
from django.conf.urls.static import static

app_name = 'dir_app'

urlpatterns=[
   path('', views.tradesmen, name='tradesmen'),
   path('register', views.register,name='register'),
   path('user_login', views.user_login,name='user_login')
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

Index.html: (Gist)

 <!DOCTYPE html>
 {% load static %}   
  <html>
   <head>
   </head>
   <body>
     <img src="{% static 'dir_app/tools.png' %}">
   </body>
  </html>

Here is where the image is stored:

location of IMAGE

Upvotes: 0

Views: 586

Answers (1)

Anwar Husain
Anwar Husain

Reputation: 1874

DEBUG should be true if want to use django.conf.url.static https://github.com/django/django/blob/926148ef019abcac3a9988c78734d9336d69f24e/django/conf/urls/static.py#L23

STATIC_ROOT should be a string, not a list. https://docs.djangoproject.com/en/3.0/ref/settings/#std:setting-STATIC_ROOT

Upvotes: 1

Related Questions