简体   繁体   English

未知命令:'collectstatic'Django 1.7

[英]Unknown command: 'collectstatic' Django 1.7

I want do static files. 我想做静态文件。 I use Django 1.7 and Python 2.7.5 and openshift hosting. 我使用Django 1.7和Python 2.7.5以及openshift托管。 When I try to run: 当我尝试运行时:

python manage.py collectstatic

I get: 我明白了:

Unknown command: 'collectstatic' Type 'manage.py help' for usage.

In my settings.py: 在我的settings.py中:

... 
INSTALLED_APPS = (
   'django.contrib.staticfiles',

   'django.contrib.admin',

   'django.contrib.auth',

   'django.contrib.contenttypes',

   'django.contrib.sessions',

   'django.contrib.messages',

   'testapp',

)

TEMPLATE_CONTEXT_PROCESSORS = (
   'django.core.context_processors.static',

)
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': os.environ['OPENSHIFT_APP_NAME'],
        'USER': os.environ['OPENSHIFT_MYSQL_DB_USERNAME'], 
        'PASSWORD': os.environ['OPENSHIFT_MYSQL_DB_PASSWORD'],
        'HOST': os.environ['OPENSHIFT_MYSQL_DB_HOST'],
        'PORT': os.environ['OPENSHIFT_MYSQL_DB_PORT'],
    }
}
STATIC_ROOT = ''    
STATIC_URL = '/static/'
...

Many people had this proble. 很多人都有这个问题。 They forgot 'django.contrib.staticfiles' in INSTALLED_APPS. 他们在INSTALLED_APPS中忘记了'django.contrib.staticfiles'。 But I have this setting. 但我有这个设置。

Ok, I run help: 好的,我运行帮助:

Options:
 -v VERBOSITY, --verbosity=VERBOSITY
                       Verbosity level; 0=minimal output, 1=normal output,
                       2=verbose output, 3=very verbose output
 --settings=SETTINGS   The Python path to a settings module, e.g.
                       "myproject.settings.main". If this isn't provided, the
                       DJANGO_SETTINGS_MODULE environment variable will be
                       used.
 --pythonpath=PYTHONPATH
                       A directory to add to the Python path, e.g.
                       "/home/djangoprojects/myproject".
 --traceback           Raise on exception
 --no-color            Don't colorize the command output.
 --version             show program's version number and exit
 -h, --help            show this help message and exit

 Traceback (most recent call last):
 ...
 File "c:\Python27\lib\os.py", line 423, in __getitem__
   return self.data[key.upper()]
 KeyError: 'OPENSHIFT_APP_NAME'

OPENSHIFT_APP_NAME - environment variable (link: https://www.openshift.com/page/openshift-environment-variables ) Can you help me? OPENSHIFT_APP_NAME - 环境变量(链接: https ://www.openshift.com/page/openshift-environment-variables)你能帮帮我吗?

It looks like it can't find the environment variable OPENSHIFT_APP_NAME . 看起来它无法找到环境变量OPENSHIFT_APP_NAME You should try setting it and see if that fixes the problem. 您应该尝试设置它,看看是否能解决问题。 Django can't import your settings because it can't find that environment variable. Django无法导入您的设置,因为它无法找到该环境变量。

Those environment variables look like they are set by openshift. 那些环境变量看起来像是由openshift设置的。 You are probably running that collectstatic command in a shell that has not had them set. 您可能正在未设置它们的shell中运行该collectstatic命令。 You'll either need to set them in the shell or edit your settings.py to be able to handle this situation. 您需要在shell中设置它们或编辑settings.py才能处理这种情况。 Something like this would work: 像这样的东西会起作用:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': os.environ.get('OPENSHIFT_APP_NAME', 'A sensible default'),

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM