0

I am trying to link my css files to my Django Project. Not sure where the error is.

This is how my settings file look like:

STATICFILES_FINDERS = (
    '/Users/IMAC/work3/Blog/Blog/polls/static',
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
#    'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
STATIC_ROOT = ''
STATIC_URL = '/Users/IMAC/work3/Blog/Blog/polls/static' 

This is how my html file looks like:

<meta name="viewport" content="width=device-width">
  <link rel="stylesheet" href="{{ STATIC_URL }}gameserver.css">

This is how my css file looks like:

#tuna{color:red;} 
body {background-color:blue;}

Must i change anything else? Why might be my error? Not sure where I am making my mistake...

Where should my static folder be? inside the app or inside the same folder as the app?

5
  • at what location gameserver.css is searching currently Commented Jun 6, 2012 at 8:52
  • in my static folder which is in my app polls... Commented Jun 6, 2012 at 8:54
  • Post here STATIC_ROOT and STATIC_URL from your settings.py file Commented Jun 6, 2012 at 9:04
  • Never hardcode an absolute path !!!! Commented Jun 6, 2012 at 9:16
  • @jpic agree with you.... Commented Jun 6, 2012 at 9:20

3 Answers 3

1

Remove '/Users/IMAC/work3/Blog/Blog/polls/static' from STATICFILES_FINDERS = (

And your STATIC_ROOT should be

STATIC_ROOT = '/Users/IMAC/work3/Blog/Blog/polls/static/' 

and

STATIC_URL  = '/static/'
Sign up to request clarification or add additional context in comments.

10 Comments

gameserver.css will be in your STATIC_ROOT
what about STATICFILES_DIRS? do i need to change it as well?
put STATIC_ROOT and STATIC_URL above STATICFILES_FINDERS
STATICFILES_DIRS is Additional locations of static files . so if you have other locations too then keep it
should it the static folder be outside or inside the app?
|
0

You've misunderstood what the various settings do:

  • STATIC_FILES_FINDERS is a list of Python classes which Django uses to search for static files, it is not a list of places where static files are stored.
  • STATIC_ROOT is the directory where the static files are stored.
  • STATIC_URL is the URL that should point to the static files.

In your case you want something like this:

STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
#    'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
STATIC_ROOT = '/Users/IMAC/work3/Blog/Blog/polls/static' 
STATIC_URL = '/static/'

Comments

0

My mistake is i forgot context_instance=RequestContext(request).

If {{ STATIC_URL }} isn't working in your template, you're probably not using RequestContext when rendering the template

Comments

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.