14

I'm deploying a Django application on heroku.

In my settings module, I have configured to host static files like

STATIC_ROOT = os.path.join(BASE_DIR, 'static_my_project')
STATIC_URL = '/static/'

STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'static_my_project')
]

MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'static_cdn', 'media_root')

and urls.py

urlpatterns = urlpatterns + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns = urlpatterns + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

But on deployment to heroku, it gives error as

SystemCheckError: System check identified some issues:

ERRORS:
?: (staticfiles.E002) The STATICFILES_DIRS setting should not contain the STATIC_ROOT setting.
Anuj TBE
  • 9,198
  • 27
  • 136
  • 285
  • 10
    if the static root is the same with static_dirs, no need to set it in your settings. STATICFILES_DIRS is the list of folders where Django will search for additional static files, in addition to each static folder of each app installed. STATIC_ROOT is the folder where every static files will be stored after a manage.py collectstatic – Lemayzeur Feb 21 '18 at 19:21
  • [Please folllow this link](https://stackoverflow.com/questions/12161271/can-i-make-staticfiles-dir-same-as-static-root-in-django-1-3) - I have found the answer from stackoverflow – Madiyor Jan 22 '20 at 06:22

2 Answers2

3

Maybe this will help:

STATIC_URL = '/static/'
    
if not DEBUG:
    STATIC_ROOT = ''
    
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'static/'),
]
Meraj al Maksud
  • 1,528
  • 2
  • 22
  • 36
jack
  • 31
  • 3
1

The problem is in the STATIC_ROOT and STATICFILES_DIRS there names cant be same. static root is used for collectstatic command of django. You can remove it if not using it. And can also remove static files dirs if not changing its default position(inside django app) to somewhere else like base or something.

Amit
  • 73
  • 5
  • the error I have after removing STATIC_ROOT: You're using the staticfiles app without having set the STATIC_ROOT setting to a filesystem path – cwhisperer Sep 16 '22 at 12:19