-1

I have a problem using css in my django template,

In my settings.py i have this :

BASE_DIR = os.path.abspath(os.path.dirname(__file__) + '/')
STATIC_URL = BASE_DIR + '/static/'

In my paths I have the folder "static/css/home_css.css"

In my template home.html I have the link tag :

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

but it doens't work in order to render de css. If anybody knows what happens please

karthikr
  • 97,368
  • 26
  • 197
  • 188
rayashi
  • 1,721
  • 3
  • 20
  • 28

3 Answers3

2

STATIC_URL shouldn't point to the path in the filesystem. STATIC_ROOT should.

import os

STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = "/static/"
Aidas Bendoraitis
  • 3,965
  • 1
  • 30
  • 45
1

In your settings.py add 'django.core.context_processors.static', at TEMPLATE_CONTEXT_PROCESSORS like in this example:

TEMPLATE_CONTEXT_PROCESSORS = (
    'django.contrib.auth.context_processors.auth',
    'django.core.context_processors.debug',
    'django.core.context_processors.i18n',
    'django.core.context_processors.media',
    'django.core.context_processors.static',
    'django.core.context_processors.request',
    'django.contrib.messages.context_processors.messages',
)

EDIT

And if you're working with the local dev-server you'll need something like this in your urls.py:

(r'static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': '%s' % os.path.join(os.path.dirname(os.path.abspath(__file__)), 'static')}),

Thomas Schwärzl
  • 9,518
  • 6
  • 43
  • 69
  • do you work with developement-server or production (e.g. apache)? What is shown when you type the URL to the CSS into your browser? Do you get a 404-Error? – Thomas Schwärzl Sep 27 '12 at 20:02
0

I solved it! I put my directory static into aplication root path, and set STATIC_URL = '/static/'

thanks

rayashi
  • 1,721
  • 3
  • 20
  • 28