Python 无法执行 collectstatic

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23215581/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 02:31:11  来源:igfitidea点击:

Unable to perform collectstatic

pythondjangodjango-staticfiles

提问by user3383301

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

我是 Django 的新手!当我使用命令时出现python manage.py collectstatic此错误

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

DEBUG = True

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

我怎样才能解决这个问题?否则缺少任何安装包?

采纳答案by dhana

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

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

回答by Sheesh Mohsin

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

您必须在 settings.py 中的 STATIC_ROOT 中提供路径,其中收集所有静态文件,例如:-

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

STATIC_URL = '/static/'

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

    )

回答by ehacinom

I had to put STATIC_ROOTand STATIC_URLabove the STATICFILES_DIRSdeclaration.

我只好把STATIC_ROOTSTATIC_URL上述STATICFILES_DIRS声明。

回答by Raoof Arakkal

回答by sebuhi

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

回答by Mayur Raj

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

您可以在任何子文件夹中创建“静态”文件夹,并在其中包含所需的文件。在 settings.py 中添加以下代码行:

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 collectstatica new static folder will be created in your parent App folder

运行 python manage.py collectstatic后将在您的父 App 文件夹中创建一个新的静态文件夹

回答by ChandimaJay

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