未知命令:'collectstatic'Django 1.7

时间:2013-10-06 15:09:29

标签: python django openshift

我想做静态文件。我使用Django 1.7和Python 2.7.5以及openshift托管。当我尝试跑步时:

python manage.py collectstatic

我明白了:

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

在我的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/'
...

很多人都有这个问题。他们在INSTALLED_APPS中忘记了'django.contrib.staticfiles'。但我有这个设置。

好的,我跑了帮助:

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 - 环境变量(链接:https://www.openshift.com/page/openshift-environment-variables) 你能救我吗?

1 个答案:

答案 0 :(得分:2)

看起来它无法找到环境变量OPENSHIFT_APP_NAME。您应该尝试设置它,看看是否能解决问题。 Django无法导入您的设置,因为它无法找到该环境变量。

这些环境变量看起来像是由openshift设置的。您可能正在未设置它们的shell中运行该collectstatic命令。您需要在shell中设置它们或编辑settings.py才能处理这种情况。像这样的东西会起作用:

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