3

我正在使用 django-pipeline 来缩小我的 CSS。在我使用 PipelineCachedStorage 之前,一切都会正确缩小,因此我可以获得版本化的缓存破坏文件名。我收到以下错误:

ValueError: The file 'img/glyphicons-halflings.png' could not be found with <pipeline.storage.PipelineCachedStorage object at 0x19069d0>

我已经对项目中的所有文件进行了 grep 处理,发现这个 PNG 在 bootstrap.css 中,但我没有包含要缩小的文件。这是我的 django-pipeline 特定设置:

PIPELINE_CSS = {
    'ab': {
        'source_filenames': (
            'main.css',
            'segment-animation.css',
            ),
        'output_filename' : 'ab.css',
        }
}

PIPELINE_YUGLIFY_BINARY = '/home/redacted/ts/redacted/node_modules/yuglify/bin/yuglify'
STATICFILES_STORAGE = 'pipeline.storage.PipelineCachedStorage'

提前致谢!

编辑:

管道的新设置:

PIPELINE_COMPILERS = (
  'pipeline.compilers.less.LessCompiler',
)

PIPELINE_CSS = {
    'ab': {
        'source_filenames': (
            'bootstrap-less/bootstrap.less',
            'main.css',
            'segment-animation.css',
            ),
    'output_filename' : 'ab.css',
        }
}

PIPELINE_YUGLIFY_BINARY = '/home/redacted/ts/redacted/node_modules/yuglify/bin/yuglify'
STATICFILES_STORAGE = 'pipeline.storage.PipelineCachedStorage'
4

2 回答 2

6

该错误与 Pipeline 并不完全相关,而是与 Django扩展的CachedStaticFilesStorage内容有关。PipelineCachedStorage缓存的存储将在您的 css 文件中查找文件引用,并使用附加了 md5 哈希的版本的适当链接替换url('asset-link')和。@import 'resource-link'

这将url('img/glyphicons-halflings.png')变成url('img/glyphicons-halflings.<hash>.png'). 因此,如果您的 css 文件中有资产引用但没有基础资产,则post_process()ofCachedStaticFilesStorage将引发该错误。

你可以在这里阅读更多。我建议使用 django 管道编译较少版本的引导程序,并删除您不需要的较少组件,例如如果您不想包含引导程序图标的图标。或者,您可以包含适当的资产。

于 2013-10-25T18:40:15.527 回答
2

我发现django-pipeline-forgiving包很好地解决了这个问题与股票 Django CachedStaticFilesStorage / PipelineCachedStorage

于 2014-12-01T02:35:07.647 回答