无法使用django-pipeline和YUI压缩文件

时间:2012-07-05 00:25:17

标签: django yui-compressor django-compressor

当我运行 python manage.py collectstatic 时,我得到:

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/fceruti/Development/Arriendas.cl/venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
    utility.execute()
  File "/Users/fceruti/Development/xxxxx/venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/fceruti/Development/xxxxx/venv/lib/python2.7/site-packages/django/core/management/base.py", line 196, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/Users/fceruti/Development/xxxxx/venv/lib/python2.7/site-packages/django/core/management/base.py", line 232, in execute
    output = self.handle(*args, **options)
  File "/Users/fceruti/Development/xxxxx/venv/lib/python2.7/site-packages/django/core/management/base.py", line 371, in handle
    return self.handle_noargs(**options)
  File "/Users/fceruti/Development/xxxxx/venv/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 163, in handle_noargs
    collected = self.collect()
  File "/Users/fceruti/Development/xxxxx/venv/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 119, in collect
    dry_run=self.dry_run)
  File "/Users/fceruti/Development/xxxxx/venv/lib/python2.7/site-packages/pipeline/storage.py", line 30, in post_process
    packager.pack_stylesheets(package)
  File "/Users/fceruti/Development/xxxxx/venv/lib/python2.7/site-packages/pipeline/packager.py", line 90, in pack_stylesheets
    variant=package.variant, **kwargs)
  File "/Users/fceruti/Development/xxxxx/venv/lib/python2.7/site-packages/pipeline/packager.py", line 100, in pack
    content = compress(paths, **kwargs)
  File "/Users/fceruti/Development/xxxxx/venv/lib/python2.7/site-packages/pipeline/compressors/__init__.py", line 72, in compress_css
    css = self.concatenate_and_rewrite(paths, output_filename, variant)
  File "/Users/fceruti/Development/Arriendas.cl/venv/lib/python2.7/site-packages/pipeline/compressors/__init__.py", line 135, in concatenate_and_rewrite
    content = self.read_file(path)
  File "/Users/fceruti/Development/xxxxx/venv/lib/python2.7/site-packages/pipeline/compressors/__init__.py", line 208, in read_file
    file = default_storage.open(path, 'rb')
  File "/Users/fceruti/Development/xxxxx/venv/lib/python2.7/site-packages/django/core/files/storage.py", line 33, in open
    return self._open(name, mode)
  File "/Users/fceruti/Development/xxxxx/venv/lib/python2.7/site-packages/pipeline/storage.py", line 114, in _open
    storage = self.find_storage(name)
  File "/Users/fceruti/Development/xxxxx/venv/lib/python2.7/site-packages/pipeline/storage.py", line 111, in find_storage
    raise ValueError("The file '%s' could not be found with %r." % (name, self))
ValueError: The file 'css/960_24_col.css' could not be found with <pipeline.storage.PipelineFinderStorage object at 0x101da4d50>.

当我运行 python manage.py findstatic css / 960_24_col.css 时,我得到了

Found 'css/960_24_col.css' here:
  /Users/fceruti/Development/xxxxxxx/Arriendas/static/css/960_24_col.css

我的设置是:

STATIC_ROOT = os.path.join(PROJECT_ROOT, 'static')

STATICFILES_DIRS = (
    ('css', os.path.join(STATIC_ROOT, 'css')),
    ('img', os.path.join(STATIC_ROOT, 'img')),
    ('js', os.path.join(STATIC_ROOT, 'js')),
    ('fonts', os.path.join(STATIC_ROOT, 'fonts')),
)

STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
PIPELINE = True
PIPELINE_CSS = {
    'app': {
        'source_filenames': (
            'css/960_24_col.css',
            'css/base.scss',
        ),
        'output_filename': 'css/app.css',
        'extra_context': {
            'media': 'screen,projection',
        },
    },
}
PIPELINE_CSS_COMPRESSOR = 'pipeline.compressors.yui.YUICompressor'
PIPELINE_JS_COMPRESSOR = 'pipeline.compressors.yui.YUICompressor'
PIPELINE_YUI_CSS_ARGUMENTS = ''
PIPELINE_YUI_JS_ARGUMENTS = ''
PIPELINE_YUI_BINARY = os.path.join(PROJECT_ROOT, 'libs/yuicompressor-2.4.7/build/yuicompressor-2.4.7.jar')

STATICFILES_STORAGE = 'pipeline.storage.PipelineCachedStorage'
PIPELINE_SASS_BINARY = '/usr/bin/sass'

当我添加

PIPELINE_COMPILERS = (
    'pipeline.compilers.sass.SASSCompiler',
)

运行网页,我得到:

Exception Type: CompilerError
Exception Value:    
Unable to apply SASSCompiler compiler

我做错了什么?

编辑:

我正在使用的软件是:

  • Sass 3.1.19(Brainy Betty)
  • YUI压缩机2.4.7
  • django的流水线== 1.2.11
  • Django 1.4

2 个答案:

答案 0 :(得分:1)

首先,你不应该把jar作为PIPELINE_YUI_BINARY,但你应该指向一个用java调用jar的脚本(大多数情况下,打包时它是捆绑的)。它看起来像这样:

#!/bin/sh
java -jar "/path/to/yuicompressor-2.4.7.jar" $@

答案 1 :(得分:-1)

我认为您希望STATICFILES_DIRS看起来像这样:

STATICFILES_DIRS = ('./static/')

如果这不起作用,请尝试这样的事情。

PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__)[0: (os.path.dirname(__file__).rindex(os.sep + 'src' + os.sep))])
STATICFILES_DIRS = (os.path.join(PROJECT_ROOT, 'static/' ))

(我们的想法是将PROJECT_ROOT设置为您应用的顶级目录)

你设置它的方式将在每个子目录中查找“css / 960_24_col.css”换句话说它会查找

  • STATIC_ROOT /的 CSS / CSS /960_24_col.css
  • STATIC_ROOT / IMG / CSS / 960_24_col.css
  • STATIC_ROOT / JS / CSS / 960_24_col.css
  • STATIC_ROOT /字体/ CSS / 960_24_col.css

它找不到它,因为文件位于

STATIC_ROOT/css/960_24_col.css

通常,STATICFILES_DIRS是包含在不同应用程序中的/ static /目录的集合。如果yourApp包含myApp,并且myApp有一个静态目录,则会将yourApp的静态目录和myApps静态目录放在列表中。 Collectstatic将它们组合成STATIC_ROOT,然后在其上运行Pipeline。