Problem in part 6, CSS doesn't work

251 views
Skip to first unread message

Mikko Meronen

unread,
May 26, 2018, 9:53:31 AM5/26/18
to django...@googlegroups.com
Hi,

I can't get the CSS code to work. Link color doesn't change to green nor the background image appear.

What could be the problem? The CSS code is in Wordpad.


polls/static/polls/images/style.css:

li a {
color: green;
}

body {
background: white url("images/background.gif") no-repeat;
}




polls/templates/polls/index.html:

{% if latest_question_list %}
    <ul>
    {% for question in latest_question_list %}
        <li><a href="{% url 'polls:detail' question.id %}">{{ question.question_text }}</a></li>
    {% endfor %}
    </ul>
{% else %}
    <p>No polls are available.</p>
{% endif %}

{% load static %}

<link rel="stylesheet" type="text/css" href="{% static 'polls/style.css' %}" />



Best regards,

Mikko

Dylan Reinhold

unread,
May 26, 2018, 10:31:40 AM5/26/18
to django...@googlegroups.com
Mikko,
  Your css file is polls/static/polls/images/style.css but you are trying to link to polls/style.css which would be [ olls/static/polls/style.css ]

Move your style.css file one folder folder down into polls/static/polls/style.css

Dylan

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAGD0jjK-CUUcUe9oTNqCLt%2BGTVkro2eGc12XcjiqsMj7xdZcBQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Mikko Meronen

unread,
May 26, 2018, 10:43:58 AM5/26/18
to django...@googlegroups.com
Hi,

Still the same problem :(

Mikko

Mikko Meronen

unread,
May 26, 2018, 10:48:08 AM5/26/18
to django...@googlegroups.com
In PowerShell it says:

[26/May/2018 17:45:14] "GET /static/polls/style.css HTTP/1.1" 404 1669

s.f.w...@googlemail.com

unread,
May 29, 2018, 7:23:16 AM5/29/18
to Django users
Make sure that you add the following line to your settings.py:
INSTALLED_APPS = [
'YOUR_APP_NAME',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
] 

In your case YOUR_APP_NAME should be polls.
Only with this line set, django looks in polls/static/polls/ for static (e.g .css) files.

Mikko Meronen

unread,
May 29, 2018, 1:47:08 PM5/29/18
to django...@googlegroups.com
Hi,

Thank you, but I should have those correct.

I did some googling and ran following: python manage.py collectstatic

And I got this:

Django-project\lib\site-packages\django\contrib\staticfiles\storage.py", line 43, in path
    raise ImproperlyConfigured("You're using the staticfiles app "
django.core.exceptions.ImproperlyConfigured: You're using the staticfiles app without having set the STATIC_ROOT setting to a filesystem path.

If any advices available, I would appreciate it a lot, thank you.

-Mikko

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

Vijay Khemlani

unread,
May 29, 2018, 7:17:53 PM5/29/18
to django...@googlegroups.com
That's only for production environments, for development you don't need to run that command

Where did you finally put the css file and what path did you put in the <link> tag?

On Tue, May 29, 2018 at 1:46 PM Mikko Meronen <mikkovil...@gmail.com> wrote:
Hi,

Thank you, but I should have those correct.

I did some googling and ran following: python manage.py collectstatic

And I got this:

Django-project\lib\site-packages\django\contrib\staticfiles\storage.py", line 43, in path
    raise ImproperlyConfigured("You're using the staticfiles app "
django.core.exceptions.ImproperlyConfigured: You're using the staticfiles app without having set the STATIC_ROOT setting to a filesystem path.

If any advices available, I would appreciate it a lot, thank you.

-Mikko
2018-05-29 10:18 GMT+03:00 s.f.wrobel via Django users <django...@googlegroups.com>:
Make sure that you add the following line to your settings.py:
INSTALLED_APPS = [
'YOUR_APP_NAME',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
] 

In your case YOUR_APP_NAME should be polls.
Only with this line set, django looks in polls/static/polls/ for static (e.g .css) files.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

Mikko Meronen

unread,
May 30, 2018, 10:37:11 AM5/30/18
to django...@googlegroups.com
Hi,

The css file is in .../polls/static/polls/style.css

And here is the full code of .../polls/templates/polls/index.html:

{% load static %}

<link rel="stylesheet" type="text/css" href="{% static 'polls/style.css' %}" />

{% if latest_question_list %}
    <ul>
    {% for question in latest_question_list %}
        <li><a href="{% url 'polls:detail' question.id %}">{{ question.question_text }}</a></li>
    {% endfor %}
    </ul>
{% else %}
    <p>No polls are available.</p>
{% endif %}



And this is the PowerShell I get when opening the webpage:

[30/May/2018 17:26:42] "GET /polls/ HTTP/1.1" 200 169
[30/May/2018 17:26:42] "GET /polls/static/polls/style.css HTTP/1.1" 404 1681
Not Found: /favicon.ico
[30/May/2018 17:26:43] "GET /favicon.ico HTTP/1.1" 404 2088


-Mikko

To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
Reply all
Reply to author
Forward
0 new messages