3

I'm using django-pipeline to minify my CSS. Everything minifies correctly until I use PipelineCachedStorage so I can get the versioned, cache-busting filenames. I get the following error:

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

I've grepped all the files in my project and have found that this PNG is in bootstrap.css, but I am not including that file to be minified. Here's my django-pipeline specific settings:

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'

Thanks in advance!

EDIT:

new settings for pipeline:

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'
threejeez
  • 2,314
  • 6
  • 30
  • 51

2 Answers2

6

The error isn't entirely related to Pipeline but rather what Django's CachedStaticFilesStorage that PipelineCachedStorage extends. The cached storage will look for file references in your css files and replace url('asset-link') and @import 'resource-link' with the appropriate link to the version with the md5 hash appended to it.

This will turn url('img/glyphicons-halflings.png') into url('img/glyphicons-halflings.<hash>.png'). So if you have asset references in your css files but don't have the underlying assets, the post_process() of CachedStaticFilesStorage is going to throw that error.

You can read more here. I'd recommend to compile the less version of bootstrap with django pipeline and remove the less components that you don't need, such as the icons if you don't want to include the bootstrap icons. Or you can include the appropriate assets.

Tim Edgar
  • 2,143
  • 14
  • 11
  • What do you mean by the "less version of bootstrap"? Do you mean bootstrap.min.css instead of bootstrap.css? – threejeez Oct 25 '13 at 18:53
  • https://github.com/twbs/bootstrap/tree/master/less You can use django-pipeline to compile less into css as well. Alternatively you can just go through bootstrap.css and removing the offending lines. – Tim Edgar Oct 25 '13 at 19:01
  • Ah, right, got it. I'll give this a try when I'm back behind my computer and let you know how it goes. Thanks!! – threejeez Oct 25 '13 at 19:40
  • 1
    I've made some progress (installed ruby, lessc, etc), but I'm running into another error: `IOError: [Errno 2] No such file or directory: u'/home/redacted/ts/redacted/redacted/assets/bootstrap-less/bootstrap.css'`. Why would it be looking for that file? It doesn't exist in the bootstrap.less package and it isn't specified anywhere. I posted my additions to my settings file in my original post. – threejeez Oct 25 '13 at 21:03
  • Is this error during collectstatic? Or is this in the development server? – Tim Edgar Oct 25 '13 at 22:46
  • does it work in the development server? It sounds like it can't find the less compiler. It needs to compile it first to file.css, then merge and then compress. So when it can't find the file, it would indicate that the file wasn't generated. You may need to define the path to the binary if your environment doesn't have the ability to call lessc. – Tim Edgar Oct 26 '13 at 05:26
  • I actually decided to pull bootstrap resources from a CDN. Thanks for all your help!! – threejeez Oct 28 '13 at 04:40
  • I actually have the exact same problem as @threejeez was describing, so if anybody knows the answer, please share! – airstrike May 26 '14 at 19:52
2

I've found the django-pipeline-forgiving package resolves this issue with the stock Django CachedStaticFilesStorage / PipelineCachedStorage very nicely

stealthwang
  • 915
  • 6
  • 8