Unable to perform collectstatic

六月ゝ 毕业季﹏ 提交于 2019-12-03 01:34:27

问题


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 ?


回答1:


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




回答2:


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

    )



回答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




回答4:


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




回答5:


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

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




回答6:


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


来源:https://stackoverflow.com/questions/23215581/unable-to-perform-collectstatic

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!