Question

I have a Django app that runs static files fine locally. When I push to Heroku, it's looking for static files in a different location (home/www_dev/www_dev/settings/static).

File Structure:

home
> www_dev
>>> organizations (my app)
>>> static
>>> www_dev
>>>>> settings

base.py settings: (used Two Scoops of Django template)

STATIC_ROOT = normpath(join(SITE_ROOT, 'assets'))
STATIC_URL = '/static/'
STATICFILES_DIRS = (
    normpath(join(SITE_ROOT, 'static')),
)
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)

production.py settings (used Heroku documentation)

# Static asset configuration
import os
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = 'staticfiles'
STATIC_URL = '/static/'

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
)

wsgi.py

import os
from os.path import abspath, dirname
from sys import path

SITE_ROOT = dirname(dirname(abspath(__file__)))
path.append(SITE_ROOT)

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "www_dev.settings.production")

from django.core.wsgi import get_wsgi_application
from dj_static import Cling

application = Cling(get_wsgi_application())

Procfile

web: gunicorn --pythonpath www_dev www_dev.wsgi -b 0.0.0.0:$PORT

Tried adding to urls.py per other Stack Overflow posts, did not work:

if not settings.DEBUG:
    urlpatterns += patterns('',
        (r'^static/(?P<path>.*)$', 'django.contrib.staticfiles.views.serve', {'document_root': settings.STATIC_ROOT}),
    )

Heroku error:

-----> Preparing static assets
       Collectstatic configuration error. To debug, run:
       $ heroku run python ./www_dev/manage.py collectstatic --noinput

Result from running collectstatic:

OSError: [Errno 2] No such file or directory: '/app/www_dev/www_dev/settings/static'

I'm willing to just go to S3 if I can't solve this issue, but having trouble finding a good workflow for pushing static (CSS/JS) local to S3 with django-storages and boto. Would be find with having all media on S3. Any help is much appreciated!

Was it helpful?

Solution

Change the STATIC_ROOT in your settings/production.py

If you don't need to use a different static root directory, you can simply delete the variable since it has been defined in the setting/base.py

The heroku doc assumes that you use a single settings.py file which locates in project_dir/settings.py.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top