Collecting staticfiles throws ImproperlyConfigured

Django

Django Problem Overview


I'm using Django 1.7. When deploying my site to a Production server and running collectstatic, I get following error message: django.core.exceptions.ImproperlyConfigured: The STATICFILES_DIRS setting should not contain the STATIC_ROOT setting

I use split settings; my production local.py contains:

STATIC_ROOT = '/home/username/projects/site/static/'

and my base.py contains:

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

Django Solutions


Solution 1 - Django

According to the docs, collectstatic will copy the files from various folders into STATIC_ROOT.

Therefore, you cannot use the STATIC_ROOT folder in STATICFILES_DIRS.

Solution: change STATIC_ROOT to e.g. STATIC_ROOT = '/home/username/projects/site/assets/'

Solution 2 - Django

I faced same error like this (staticfiles.E002) The STATICFILES_DIRS setting should not contain the STATIC_ROOT setting. when i try to use compressor

Main problem is My settings.py file

STATIC_ROOT = os.path.join(BASE_DIR, 'static') STATICFILES_DIRS = [os.path.join(BASE_DIR, "static")]

Remove or comment :

STATICFILES_DIRS = [os.path.join(BASE_DIR, "static")]

Solution 3 - Django

I know it is an old post but this solution has worked for me and might help someone else.

In settings.py:

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

Solution 4 - Django

The solution is that the STATIC_ROOT must not be set if you are running the Django development server:

import sys
if sys.argv[1] != 'runserver':
    STATIC_ROOT = os.path.join(BASE_DIR, "static")

Tested with Django 2.1 in a Windows 10 development environment and in an Ubuntu 18.04 docker container on AWS in a production environment.

Solution 5 - Django

in settings.py set static root to virtual environment so that it collects the static files to folder static_in_env

STATIC_ROOT=os.path.join(VENV_PATH,'static_in_env/')

Solution 6 - Django

saw this in Django 1.11 documentation

urlpatterns = [
    # ... the rest of your URLconf goes here ...
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

Once you make changes to the urls.py as shown above, it should work fine.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSaeXView Question on Stackoverflow
Solution 1 - DjangoSaeXView Answer on Stackoverflow
Solution 2 - DjangoMr SinghView Answer on Stackoverflow
Solution 3 - DjangoLuis ValverdeView Answer on Stackoverflow
Solution 4 - DjangoMenno ManheimView Answer on Stackoverflow
Solution 5 - DjangoDeepak ChowdaryView Answer on Stackoverflow
Solution 6 - DjangoArun RajView Answer on Stackoverflow