-1

I am trying to go though Django tutorial which explains about static files, but when I am trying implement that I am getting following error:

[08/Oct/2017 23:08:27] "GET / HTTP/1.1" 200 365
[08/Oct/2017 23:08:27] "GET /static/polls/sytle.css HTTP/1.1" 404 1658

My Django project structure: (removing irrelevant files and folders).

rehman@linux-desktop ~/django_proj/my_site $ tree
.
├── db.sqlite3
├── manage.py
├── my_site
│   ├── __init__.py
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
├── polls
│   ├── admin.py
│   ├── apps.py
│   ├── __init__.py
│   ├── models.py
│   ├── static
│   │   └── polls
│   │       ├── images
│   │       │   └── background.jpg
│   │       └── style.css
│   ├── templates
│   │   └── polls
│   │       ├── details.html
│   │       ├── index.html
│   │       └── result.html
│   ├── tests.py
│   ├── urls.py
│   └── views.py
└── templates

settings.py (partial contents):

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
DEBUG = True

INSTALLED_APPS = [
    'polls.apps.PollsConfig',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]
LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'Asia/Kolkata'

USE_I18N = True

USE_L10N = True

USE_TZ = True

STATIC_URL = '/static/'

url.py:

urlpatterns = [
    url(r'^', include('polls.urls')),
    url(r'^admin/', admin.site.urls),
]

index.html:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Polls</title>
    {% load static %}
    <link rel="stylesheet" type="text/css" href="{% static 'polls/sytle.css' %}" />
</head>
<body>
{% if latest_question_list %}
<ul>
    {% for q in latest_question_list %}
    <li><a href="{% url 'polls:details' q.id %}">{{ q.question_text }}</a></li>
    {% endfor %}
</ul>
{% else %}
    <p>no poll found</p>
{% endif %}

</body>
</html>

HTML code from browser:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Polls</title>
    
    <link rel="stylesheet" type="text/css" href="/static/polls/sytle.css" />
</head>
<body>

<ul>
    
    <li><a href="/3/">Question 2</a></li>
    
    <li><a href="/2/">Question 1</a></li>
    
    <li><a href="/1/">Whats new?</a></li>
    
</ul>


</body>
</html>

I spent significant time searching on net on possible pitfalls and trying to find my the issue here, but I couldn't find any solution.

Anyone able to spot any error or issues on my code by which Django not able to display static page.

Jason Aller
  • 3,541
  • 28
  • 38
  • 38

1 Answers1

1

Typo: you are using sytle.css in place of style.css

<link rel="stylesheet" type="text/css" href="{% static 'polls/style.css' %}" />
                                                              ^^^^^^
Astik Anand
  • 12,757
  • 9
  • 41
  • 51