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" >
user671800
  • 11
  • 1
  • 4

1 Answers1

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',

dting
  • 38,604
  • 10
  • 95
  • 114
  • also, the STATICFILES_DIRS needs to be a list or tuple, AND, they need to be absolute paths. I assume `.../Templates` is not `/Templates`. – Yuji 'Tomita' Tomita Mar 22 '11 at 19:21
  • good points, although i think the trailing comma will tuplize(?) it. – dting Mar 22 '11 at 19:24
  • 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 – user671800 Mar 22 '11 at 20:47
  • check to see if your css file is being hosted... type into your browers `http:///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. – dting Mar 22 '11 at 21:46