【问题标题】:manage.py collectstatic command not found, Django 1.5.1找不到 manage.py collectstatic 命令,Django 1.5.1
【发布时间】:2014-02-12 22:36:08
【问题描述】:

我对 python 很陌生,当我运行时

$ python manage.py collectstatic

命令,它返回

'未知命令:'collectstatic''

根据我的研究发现,settings.py 似乎有问题,这是我的 settings.py:

import os
DEBUG = True
TEMPLATE_DEBUG = DEBUG

ADMINS = (
    # ('', 'your_email@example.com'),
)

MANAGERS = ADMINS

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3', 
        'NAME': 'basic_code.sqlite3',                     
        # The following settings are not used with sqlite3:
        'USER': '',
        'PASSWORD': '',
        'HOST': '',                      # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
        'PORT': '',                      # Set to empty string for default.
    }
}


ALLOWED_HOSTS = []


TIME_ZONE = 'America/Chicago'

LANGUAGE_CODE = 'en-us'

SITE_ID = 1

USE_I18N = True

USE_L10N = True

USE_TZ = True

MEDIA_ROOT = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'static/media')

MEDIA_URL = '/media'

STATIC_ROOT = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'static/static-only')

STATIC_URL = '/static/'

STATICFILES_DIRS = (
    os.path.join(os.path.dirname(os.path.dirname(__file__)), 'static/static'),
)

STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
#    'django.contrib.staticfiles.finders.DefaultStorageFinder',
)

# Make this unique, and don't share it with anybody.
SECRET_KEY = 'XXXXXXXXXX'

# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
#     'django.template.loaders.eggs.Loader',
)

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    # Uncomment the next line for simple clickjacking protection:
    # 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

ROOT_URLCONF = 'basic_code.urls'

WSGI_APPLICATION = 'basic_code.wsgi.application'

TEMPLATE_DIRS = (
    os.path.join(os.path.dirname(os.path.dirname(__file__)), 'static/templates'),
)

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.admin',
    'django.contrib.admindocs',
    'contact',
)


LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'filters': {
        'require_debug_false': {
            '()': 'django.utils.log.RequireDebugFalse'
        }
    },
    'handlers': {
        'mail_admins': {
            'level': 'ERROR',
            'filters': ['require_debug_false'],
            'class': 'django.utils.log.AdminEmailHandler'
        }
    },
    'loggers': {
        'django.request': {
            'handlers': ['mail_admins'],
            'level': 'ERROR',
            'propagate': True,
        },
    }
}

非常感谢!非常感谢任何帮助。

【问题讨论】:

  • 在终端中输入“python manage.py”,看看是否在输出列表中看到“collectstatic”。如果它在那里,那么你应该能够运行它。
  • manage.py 命令是否正在加载您的设置文件?尝试使用python manage.py collectstatic --settings=path.to.settings 明确指定它。请注意,这使用的是不包含 py 扩展名的虚线路径,而不是文件路径。
  • Aron,我输入 python manage.py 时它不在列表中
  • Jonafato,当我这样做时它会抛出 2 个错误。 “不支持按文件名导入”和“无法导入设置”

标签: python django


【解决方案1】:

将媒体网址从 /media 更改为 /media/

下次遇到这样的问题,试试runserver,如果不行,检查trace。

【讨论】:

  • 做到了!非常感谢你,我真的很感谢你的帮助!我在这坐了好几个小时。你就是男人!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-09-24
  • 2014-09-02
  • 1970-01-01
  • 2013-10-13
  • 2020-12-05
  • 2012-12-13
  • 1970-01-01
相关资源
最近更新 更多