0

I am using Django and I can't get my style.css to work. Every time I load the page I am working on, no css is applied. Also I get this in the terminal "GET /css/style.css HTTP/1.1" 404 2239

My style.css is located in .../Templates/site_media/static/css

I also have djago.contrib.staticfiles in my INSTALLED_APPS

I have this in my settings.py

STATIC_URL = '/static/'


STATICFILES_DIRS = "/Templates/site_media/",

This is what I have in my template to load the css

<link href="{{STATIC_URL}}css/style.css" rel="stylesheet" type="text/css" >
2
  • When you view the HTML, what does it show as the href? Is the STATIC_URL variable passed through to the template? Commented Mar 22, 2011 at 19:25
  • What do you mean by is the STATIC_URL variable passed through to the template? I used the <link href={{STATIC_URL}}static/css/style.css ....> Commented Mar 22, 2011 at 20:49

1 Answer 1

2

My style.css is located in .../Templates/site_media/static/css

doesnt match

<link href="{{STATIC_URL}}css/style.css" rel="stylesheet" type="text/css" >

you would need to have your link as:

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

Edit Use absolute paths for STATICFILES_DIRS (thx Yuji):

settings.py:

import os
SITE_ROOT = os.path.dirname(os.path.realpath(__file__))

STATIC_URL = '/static/'
STATICFILES_DIRS = ((os.path.join(SITE_ROOT,'Templates/site-media'),)

make sure that your:

TEMPLATE_CONTEXT_PROCESSORS has 'django.core.context_processors.static',

Sign up to request clarification or add additional context in comments.

4 Comments

also, the STATICFILES_DIRS needs to be a list or tuple, AND, they need to be absolute paths. I assume .../Templates is not /Templates.
good points, although i think the trailing comma will tuplize(?) it.
I changed my settings.py to the suggestions that kriegar suggested and it still doesn't work. I get this now in the terminal though "GET /static/css/style.css HTTP/1.1" 404 1730
check to see if your css file is being hosted... type into your browers http://<site>/static/static/css/style.css if you don't want the redundant static you should change your STATICFILES_DIR to ((os.path.join(SITE_ROOT,'Templates/site-media/static'),) and your css file should then be hosted at /static/css/style.css. However based on the comments above it looks like your {{ STATIC_URL }} isn't reaching the template.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.