almost a beginner almost a beginner - 1 month ago 5x
CSS Question

django css setup not working

I followed some tips from related questions in here, and tried the documentation but failed so far to get css file working.

Note that css (obviously) works perfectly fine if I place it within the template, but I can't import it from static folder.

So in my app folder, I created a static folder, within which I created another folder called static: app->static->style.css

When I run collectstatic, it gets style.css, and places it in: projectfolder->static->style.css

All of this is working fine.

My static settings were set automatically, I changed it based on some answers I read in related questions, but still didn't work:

MEDIA_ROOT = u'/home/user/projectfolder/media'
MEDIA_URL = '/media/'
STATIC_ROOT = u'/home/user/projectfolder/static'
STATIC_URL = '/static/'

In my template, I have:

{% load staticfiles %}
<link rel="stylesheet" href="{{ STATIC_URL }}style.css" />

Clearly I'm missing something, when I reload the website, no css is shown. In my css I have clearly set the body background to test it, but it doesn't change.

Extra info:
- Debug is set to true
- Using the latest Django version .10

Any help or direction would be appreciated,

thanks in advance.


When you view the page's source code from what path is it trying to load your style?

Try this - <link rel="stylesheet" href="{% static "style.css" %}" />

Also I would change MEDIA_ROOT and STATIC_ROOT to MEDIA_ROOT = os.path.join(BASE_DIR, 'media') and STATIC_ROOT = os.path.join(BASE_DIR, 'static'). This way both paths are being built by the system and it's harder to mess up.