0

So I've never deployed a Django app and I'm trying to get up to speed on the whole thing. I ran the collectstatic command and now non of my static files will render. When I run the findstatic command I receive an exception that says:

django.core.exceptions.ImproperlyConfigured: The storage backend of the staticfiles finder     <class 'django.contrib.staticfiles.finders.DefaultStorageFinder'> doesn't have a valid location.

My template renders just find but I can't seem to figure out why the css file is not being found. Highlight from my settings module:

settings/
    base.py
    devel.py
    prod.py

base.py

cwd = os.path.dirname(os.path.abspath(__file__)) 
PROJECT_ROOT = cwd[:-9] # chop off "settings/"

STATICFILES_FINDERS = [
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'django.contrib.staticfiles.finders.DefaultStorageFinder',
]

TEMPLATE_LOADERS = [
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
'django.template.loaders.eggs.Loader',
]

TEMPLATE_DIRS = [
os.path.join(PROJECT_ROOT, "templates"),
]

devl.py

STATIC_URL = "/site_media/static/"

STATICFILES_DIRS = [
    os.path.join(PROJECT_ROOT, "site_media", "static"),
]

STATIC_ROOT = os.path.join(PROJECT_ROOT, "site_media", "static")

site_base.html

<link rel="stylesheet" href="{{ STATIC_URL }}css/site_base.css" />

Would appreciate your help because Im stumped.

harristrader
  • 1,181
  • 2
  • 13
  • 20
  • 1
    Got a [STATIC_ROOT](https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-STATIC_ROOT) setting? – dokkaebi Oct 25 '12 at 00:58
  • yes. static_root setting updated and included above. – harristrader Oct 25 '12 at 01:27
  • More importantly, with that finder, do you have a [DEFAULT_FILE_STORAGE](https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#staticfiles-finders) setting? – dokkaebi Oct 25 '12 at 01:30
  • Looks like the default for that is `django.core.files.storage.FileSystemStorage`. The loader looks for `storage.base_location`, and the default value of that on `FileSystemStorage` is `MEDIA_ROOT`. You could try pointing `MEDIA_ROOT` at your static files. – dokkaebi Oct 25 '12 at 02:05
  • This may all be a red herring, though, as I think `FileSystemFinder` and `AppDirectoriesFinder` should find your static files even if the third one fails. What is the path from your PROJECT_ROOT to your `site_base.css`, by the way? – dokkaebi Oct 25 '12 at 02:07
  • Thanks for your help on this. The path from the site root to the site_base.css is /tulsa/static/css/site_base.css – harristrader Oct 25 '12 at 23:34

1 Answers1

1

Update:

It turned out to be a missing context processor. To get your STATIC_URL setting inside a template, you have to register the staticfiles context processor:

TEMPLATE_CONTEXT_PROCESSORS = [
    ...
    'django.core.context_processors.static',
    ...
]

First stab:

It looks like you'll need to add that dir to your list of static sources (re: a comment above):

# list of input paths for collectstatic
STATICFILES_DIRS = [
    os.path.join(PROJECT_ROOT, "tulsa", "static"),

    # you'll want to remove this path:
    #os.path.join(PROJECT_ROOT, "site_media", "static"),
]

# output path for collectstatic
STATIC_ROOT = os.path.join(PROJECT_ROOT, "site_media", "static")
dokkaebi
  • 9,004
  • 3
  • 42
  • 60
  • When you view source on the page, what is output for {{ STATIC_URL }}? – dokkaebi Oct 26 '12 at 00:52
  • "" there is also the "page not found" template in the source view as a dropdown menu under this line. – harristrader Oct 26 '12 at 01:10
  • So that's the problem - STATIC_URL is not in your context. Could you post the View code? – dokkaebi Oct 26 '12 at 01:17
  • AH - have you registered the [staticfiles context processor](https://docs.djangoproject.com/en/dev/ref/templates/api/#django-core-context-processors-static)? – dokkaebi Oct 26 '12 at 01:27
  • Ok, so I updated the template context processor with "django.core.context_processors.static"and the html view source now reads A server error occurred. Please contact the administrator. – harristrader Oct 26 '12 at 01:45
  • Good -- it looks like your static files are in the right place now. This will be a new error. If you set `DEBUG=True`, you should get a nice error page with a stack trace. – dokkaebi Oct 26 '12 at 01:50
  • thanks so much for hanging in there with me on this. Im currently receiving this exception in the terminal: "ImproperlyConfigured: The storage backend of the staticfiles finder doesn't have a valid location." – harristrader Oct 26 '12 at 03:30
  • My third comment on your original post should lead you in the right direction for that problem, but keep in mind `collectstatic` is not required at all when using `runserver`. – dokkaebi Oct 26 '12 at 03:41
  • Thanks for this. I'm still having trouble getting the css working. I'm receiving 404 error when trying to load static urls directly. – harristrader Oct 28 '12 at 17:14