[Django]-You're using the staticfiles app without having set the STATIC_ROOT setting to a filesystem path

27šŸ‘

Summarizing ratraceā€™s answer, the main solution is to add

STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')

to settings.py. Where STATIC_ROOT is the destination to where static files are copied and from where they are served when deploying the Django app.

17šŸ‘

I was able to make this work by getting rid of the if statement all together and just having the following in my settings.py.

import dj_database_url
DATABASES = {
    'default': dj_database_url.config(default='postgres://localhost')
}

SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

ALLOWED_HOSTS = ['*']

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'
STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
)
šŸ‘¤ratrace123

3šŸ‘

I solved this issue following these three steps:

  1. Import the os module in the settings.py: import os
  2. Set the STATIC_ROOT variable to "staticfiles" in the settings.py: STATIC_ROOT = os.path.join(BASE_DIR,'staticfiles')
  3. Execute the "collectstatic" command: python manage.py collectstatic
šŸ‘¤ahnaimi

0šŸ‘

On this website it says to add this url pattern to your project:

urlpatterns += patterns(ā€, (rā€™^static/(?P.*)$ā€™, ā€˜django.views.static.serveā€™, {ā€˜document_rootā€™: settings.STATIC_ROOT}),)

I havenā€™t used heroku before but IF I understand correctly, it needs a path to send all the collected static files to. Usually thatā€™s in the serverā€™s settings. But the website above mentions that heroku uses an app which doesnā€™t support static files deployment, and thatā€™s why you need a url pattern to make it get the static files from their respective places.

Also, read the entire tutorial first. They might mention your problem somewhere near the end of the tutorial in like a Notes section. Read the comments also if they exist.

šŸ‘¤Eyad Arafat

Leave a comment