Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django The STATICFILES_DIRS setting should not contain the STATIC_ROOT setting

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.
like image 308
Anuj TBE Avatar asked Feb 21 '18 18:02

Anuj TBE


People also ask

What is Static_root in Django?

The STATIC_ROOT variable in settings.py defines the single folder you want to collect all your static files into. Typically, this would be a top-level folder inside your project, eg: STATIC_ROOT = "/home/myusername/myproject/static" # or, eg, STATIC_ROOT = os. path.

What does Collectstatic do in Django?

collectstatic. Collects the static files into STATIC_ROOT . Duplicate file names are by default resolved in a similar way to how template resolution works: the file that is first found in one of the specified locations will be used. If you're confused, the findstatic command can help show you which files are found.

What is Staticfiles_dirs?

STATICFILES_DIRS is the list of folders where Django will search for additional static files aside from the static folder of each app installed.

How does Django find static files?

Using the collectstatic command, Django looks for all static files in your apps and collects them wherever you told it to, i.e. the STATIC_ROOT . In our case, we are telling Django that when we run python manage.py collectstatic , gather all static files into a folder called staticfiles in our project root directory.


2 Answers

may be help this.

STATIC_URL = '/static/'
    
    if not DEBUG:
        STATIC_ROOT = ''
    
    STATICFILES_DIRS = [
        os.path.join(BASE_DIR, 'static/'),
    ]
like image 172
jack Avatar answered Oct 09 '22 22:10

jack


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.

like image 1
Amit Avatar answered Oct 09 '22 22:10

Amit