【问题标题】:collectstatic command is not available in Django 1.6a1collectstatic 命令在 Django 1.6a1 中不可用
【发布时间】:2013-06-27 08:49:36
【问题描述】:

我已经在我的 virtualenv 中安装了 django,如下所示:

git clone git://github.com/django/django.git django-trunk
pip install -e django-trunk/

在我的设置文件中有这个:

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.admindocs',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',
    'django.contrib.flatpages',
    'south',
    'djcelery',
    'gunicorn',
    'sorl.thumbnail',
    'template_utils',
    'compressor',
    'tagging',
    'ckeditor',
    'mptt',
)


STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    'compressor.finders.CompressorFinder',
)

当我尝试做时

python manage.py collectstatic

我收到此错误:

Unknown command: 'collectstatic'

如果我这样做

python manage.py --version

我明白了

1.6a1

为什么 collectstatic 不可用?

编辑:

当我跑步时

python manage.py --help

我明白了:

Usage: manage.py subcommand [options] [args]

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
  --version             show program's version number and exit
  -h, --help            show this help message and exit

Type 'manage.py help <subcommand>' for help on a specific subcommand.

Available subcommands:

[django]
    check
    cleanup
    compilemessages
    createcachetable
    dbshell
    diffsettings
    dumpdata
    flush
    inspectdb
    loaddata
    makemessages
    runfcgi
    runserver
    shell
    sql
    sqlall
    sqlclear
    sqlcustom
    sqldropindexes
    sqlflush
    sqlindexes
    sqlinitialdata
    sqlsequencereset
    startapp
    startproject
    syncdb
    test
    testserver
    validate

【问题讨论】:

  • 你激活你的虚拟环境了吗?根据 beta 1.6a1 的当前发行说明,collect static 应该仍然可用。
  • 是的,从我激活的 virtualenv 中运行这些命令。
  • 检查 python manage.py --help 并查看它是否已列出。也可以试试django-admin.py collectstatic。
  • 不,没有列出来。
  • 没有。我编辑了我的问题以显示我所有已安装的应用程序。

标签: django


【解决方案1】:

Django 可能加载了错误的设置文件。详情见这个问题:Django: Can't run custom commands

尝试在settings.py 文件的顶部引发异常;这会让你知道文件是否正在加载。

【讨论】:

  • 是的,就是这样!修复它:export DJANGO_SETTINGS_MODULE=myproject.settings.staging
  • 很好的答案...这个问题让我困惑了一段时间,直到这篇文章...谢谢。
【解决方案2】:

添加“STATIC_ROOT”

STATIC_ROOT = "/var/www/example.com/static/"

试试

python manage.py collectstatic

【讨论】:

    猜你喜欢
    • 2012-12-13
    • 1970-01-01
    • 2013-10-13
    • 1970-01-01
    • 2012-08-08
    • 1970-01-01
    • 2012-06-30
    • 2012-10-15
    • 2017-12-12
    相关资源
    最近更新 更多