86

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 ?

Vini.g.fer
  • 11,639
  • 16
  • 61
  • 90
user3383301
  • 1,891
  • 3
  • 21
  • 49

9 Answers9

176

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

dhana
  • 6,487
  • 4
  • 40
  • 63
  • Thanks :) Works ! Before i was using this application with static root as empty . But it worked ! What could be the problem now ? – user3383301 Apr 22 '14 at 09:39
  • You need define the static folder.So all static files are collected in that folder. `You're using the staticfiles app without having set the STATIC_ROOT setting to a filesystem path` – dhana Apr 22 '14 at 09:43
10

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'),

    )
Sheesh Mohsin
  • 1,455
  • 11
  • 28
3

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

Mayur Raj
  • 61
  • 5
2

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')
Sabuhi Shukurov
  • 1,616
  • 16
  • 17
1

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

ehacinom
  • 8,070
  • 7
  • 43
  • 65
1
STATIC_ROOT = os.path.join(BASE_DIR, 'assest')
STATICFILES_DIR = [
os.path.join(BASE_DIR, 'static')
]
  • 2
    Thank you for this code snippet, which might provide some limited, immediate help. A [proper explanation](https://meta.stackexchange.com/q/114762/349538) would greatly improve its long-term value by showing why this is a good solution to the problem and would make it more useful to future readers with other, similar questions. Please [edit] your answer to add some explanation, including the assumptions you’ve made. – codedge May 17 '20 at 18:22
  • There is a typo: "assets" – JulienD May 17 '20 at 22:55
0
STATIC_ROOT = "/var/www/YourSiteFolder/static/"
STATIC_URL = '/static/'

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

0

STATIC_URL = '/static/'

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

This works for me

enter image description here

0

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

enter image description here