Reputation: 1911
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 ?
Upvotes: 86
Views: 86870
Reputation: 15837
I can't believe that after 10 years nobody has really addressed the original problem.
Your STATIC_ROOT
is an empty string. STATIC_ROOT
is the folder where collectstatic
will place the static files.
Are you expecting Django to create a folder with an empty name? But where?
You got this error because STATIC_ROOT
is an empty string. You also get this error if you don't define STATIC_ROOT
at all in your settings.
So, just define STATIC_ROOT
with a non-empty string. It does not strictly have to be an absolute path, although the documentation states so. I also tried it with a relative path or just a folder name and it still works as expected.
Upvotes: 0
Reputation: 118
if you want to load static files rather than admin panel files or getting errors while loading webpage static files like CSS js etc
I suggest you change the folder name of 'static' to 'staticfiles'
and then add this code in your settings.py
STATICFILES_DIRS = ( os.path.join(BASE_DIR, 'staticfiles'), )
then after run python manage.py collectstatic
Then the problem will be fixed
Upvotes: -1
Reputation: 118
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR,'static')
This works for me
Upvotes: -1
Reputation: 9
STATIC_ROOT = os.path.join(BASE_DIR, 'assest')
STATICFILES_DIR = [
os.path.join(BASE_DIR, 'static')
]
Upvotes: 0
Reputation:
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
Upvotes: 2
Reputation: 1920
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')
Upvotes: 1
Reputation: 65
STATIC_ROOT = "/var/www/YourSiteFolder/static/"
STATIC_URL = '/static/'
look at https://docs.djangoproject.com/en/1.11/howto/static-files/#deployment
Upvotes: -1
Reputation: 8894
I had to put STATIC_ROOT
and STATIC_URL
above the STATICFILES_DIRS
declaration.
Upvotes: 0
Reputation: 6525
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
Upvotes: 175
Reputation: 1453
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'),
)
Upvotes: 9