Unable to perform collectstatic

PythonDjangoDjango Staticfiles

Python Problem Overview


I am new to django ! When I use the command python manage.py collectstatic I get this error

django.core.exceptions.ImproperlyConfigured: You're using the staticfiles app without having set the STATIC_ROOT setting to a filesystem path

But I can successfully run the server .

My static files declarations are :

STATIC_ROOT = ''

STATIC_URL = '/static/'


STATICFILES_DIRS = (

    ('assets', os.path.join(PROJECT_DIR, '../static')),
)

and debug is set to true

DEBUG = True

How can I fix this? Else am missing any installation packages ?

Python Solutions


Solution 1 - Python

Try this,

PROJECT_DIR = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = os.path.join(PROJECT_DIR, 'static')

Look at https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-STATIC_ROOT

Solution 2 - Python

You must have to give path in STATIC_ROOT in settings.py where all your static files are collected as for example:-

STATIC_ROOT = "app-root/repo/wsgi/static"

STATIC_URL = '/static/'

STATICFILES_DIRS = (
    ('assets', 'app-root/repo/wsgi/openshift/static'),
    
    )

Solution 3 - Python

you can create 'static' folder in any subfolder and have required files in it. In settings.py add the following lines of code:

PROJECT_DIR = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = os.path.join(PROJECT_DIR, 'static')
STATIC_URL = '/static/'

After running python manage.py collectstatic a new static folder will be created in your parent App folder

Solution 4 - Python

well had this error as well. I fixed:

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

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

Solution 5 - Python

I had to put STATIC_ROOT and STATIC_URL above the STATICFILES_DIRS declaration.

Solution 6 - Python

STATIC_ROOT = "/var/www/YourSiteFolder/static/"
STATIC_URL = '/static/'

look at https://docs.djangoproject.com/en/1.11/howto/static-files/#deployment

Solution 7 - Python

STATIC_ROOT = os.path.join(BASE_DIR, 'assest')
STATICFILES_DIR = [
os.path.join(BASE_DIR, 'static')
]

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
Questionuser3383301View Question on Stackoverflow
Solution 1 - PythondhanaView Answer on Stackoverflow
Solution 2 - PythonSheesh MohsinView Answer on Stackoverflow
Solution 3 - PythonMayur RajView Answer on Stackoverflow
Solution 4 - PythonSabuhi ShukurovView Answer on Stackoverflow
Solution 5 - PythonehacinomView Answer on Stackoverflow
Solution 6 - PythonRaoof ArakkalView Answer on Stackoverflow
Solution 7 - PythonChandimaJayView Answer on Stackoverflow