Django Collectstatic command Changed something

2.9k views Asked by At

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.

1

There are 1 answers

9
dokkaebi On

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")