Skip to content Skip to sidebar Skip to footer

Django 1.10 Templating/staticfiles Not Showing Any Images

I am trying to enable Django templating in 1.10 and it is not behaving correctly. Anything I have referenced to be called from the static files (./manage.py collectstatic) is not s

Solution 1:

You have issue in your settings file. Use that settings for static files.

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

INSTALLED_APPS = [
  'django.contrib.admin',
  'django.contrib.auth',
  'django.contrib.contenttypes',
  'django.contrib.sessions',
  'django.contrib.messages',
  'django.contrib.staticfiles', # it's is used for static files
]


STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'static')

STATICFILES_DIRS = (
    # os.path.join(os.path.dirname(BASE_DIR), 'static'),
    os.path.join(BASE_DIR, 'static'),
)

In your template you can load image like

{% load staticfiles %}  # register static tag
<img class="img-portfolio img-responsive" src="{% static 'img/portfolio-1.jpg' %}">

This image should be available in that directory structure 'static/img/portfolio-1.jpg'.

Urls.py should look like this.

urlpatterns = [
   url(r'^admin/', admin.site.urls),
   url(r'^$', index, name='index'),
   url(r'^auths/', include('auths.urls')),
   url(r'^quiz/', include('quizes.urls'))
]

please update your urls accordinlgy. This is just an example.

Post a Comment for "Django 1.10 Templating/staticfiles Not Showing Any Images"