django The STATICFILES_DIRS setting should not contain the STATIC_ROOT setting

Anuj TBE picture Anuj TBE · Feb 21, 2018 · Viewed 8.9k times · Source

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.

Answer

jack picture jack · Nov 14, 2020

may be help this.

STATIC_URL = '/static/'
    
    if not DEBUG:
        STATIC_ROOT = ''
    
    STATICFILES_DIRS = [
        os.path.join(BASE_DIR, 'static/'),
    ]