The STATICFILES_DIRS setting should not contain the STATIC_ROOT setting
Asked Answered
E

10

65

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'),
)
Evildoer answered 30/11, 2014 at 13:29 Comment(3)
possible duplicate of Can I make STATICFILES_DIR same as STATIC_ROOT in Django 1.3?Stream
Possible, but searching "django.core.exceptions.ImproperlyConfigured: The STATICFILES_DIRS setting should not contain the STATIC_ROOT setting" in Google didn't point me to that one.Evildoer
That's because you had quotes around it. That question is regarding the same problem.Stream
E
77

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/'

Evildoer answered 30/11, 2014 at 13:29 Comment(1)
The 'docs' link for Django 1.7 is no longer live, but it works if you increase the Django version number in there from 1.7 to 3.2: docs.djangoproject.com/en/3.2/ref/contrib/staticfilesPatchwork
S
40

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')
Smirch answered 11/7, 2020 at 19:46 Comment(1)
Not 100% sure, but I don't think this will interact well with collectstatic?Farwell
B
29

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")]

Belovo answered 22/2, 2018 at 9:24 Comment(3)
then how do you serve static files from the development server? (via python manage.py runserver)Taranto
will run into the error: raise ImproperlyConfigured("You're using the staticfiles app " django.core.exceptions.ImproperlyConfigured: You're using the staticfiles app without having set the STATIC_ROOT setting to a filesystem path.Bloodless
@Taranto it is advised to set STATIC_ROOT to say os.path.join(BASE_DIR, 'var', 'static') that directory will contain staticfiles copied by django if you execute collectstatic command. That command will look for static files in STATICFILES_DIRS and if you run runserver, then it will serve your static files from STATICFILES_DIRS .Robey
N
4

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.

Nauseating answered 6/8, 2020 at 9:17 Comment(0)
S
1

I got the same error below:

The STATICFILES_DIRS setting should not contain the STATIC_ROOT setting.

Because I set the same folder static to STATIC_ROOT and STATICFILES_DIRS as shown below:

# "settings.py"

STATIC_ROOT = 'static/'
STATICFILES_DIRS = [
    BASE_DIR / 'static/'
]

So, I set the different folder staticfiles to STATIC_ROOT as shown below, then the error was solved:

# "settings.py"

STATIC_ROOT = 'staticfiles/' # Here
STATICFILES_DIRS = [
    BASE_DIR / 'static/'
]
Stipend answered 27/8, 2023 at 13:57 Comment(0)
C
0

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/')
Cahier answered 5/6, 2021 at 11:25 Comment(0)
A
0

You have to enter complete path of static directory:

STATIC_ROOT = '/home/reza/blog/static/'

Or If you want to use Collects the static files into STATIC_ROOT by django-admin collectstatic command you have to use :

STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
Austro answered 9/9, 2022 at 21:22 Comment(0)
I
0

I had this problem in pythonanywhere, added:

STATIC_URL = '/static/'

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

STATIC_ROOT = '/home/user/project/'

Then run:

python3.9 manage.py collectstatic

It kind of worked, but sent the files in the main directory...

Indigestible answered 1/3, 2023 at 12:26 Comment(0)
C
0

For pythonaywhere:

1 - Add your static root in the setting.py

enter image description here

2 - Update manually the path environment into web app configuration

enter image description here

Cathead answered 8/7, 2023 at 22:31 Comment(0)
S
-4

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.

Shaw answered 10/6, 2017 at 4:20 Comment(1)
this is not suitable for production. the workaround is only used for local development!Withers

© 2022 - 2025 — McMap. All rights reserved.