light_ray
light_ray

Reputation: 644

Not able to display static images and css files

I want to display static images and CSS file

settings.py

    STATIC_PATH = os.path.join(BASE_DIR,'static')
    STATIC_URL = '/static/'
    STATICFILES_DIRS = ( BASE_DIR +"/articles/static",)
    STATIC_ROOT = os.path.join(BASE_DIR,"static",)

In Template I am trying display the images from img folder

article.html

     {% load staticfiles %}
     <img src = "{% static '/img/default-by.gif' %}" alt = "left slide"/>

Folder Structure

The folder structure where I have tried to access static images according to the django docs https://docs.djangoproject.com/en/1.9/intro/tutorial06/ Folder Structure

NewsArticles
 -->articles
   --> static
      -->articles
          -->img
            -->default-by.gif

db.sqlite3 
manage.py
media
NewsArticles
README.md
static
templates

I am using firebug to check the image location its showing as mentioned http://127.0.0.1:8000/static/img/default-by.gif

Upvotes: 3

Views: 96

Answers (1)

Muhammad Hassan
Muhammad Hassan

Reputation: 14391

You are giving wrong path for your image. It should be like this

{% load staticfiles %}
 <img src = "{% static 'articles/img/default-by.gif' %}" alt = "left slide"/>

Hope this will works.

Upvotes: 1

Related Questions