Michael Bates
Michael Bates

Reputation: 1934

django-pipeline throwing ValueError: the file could not be found

When running python manage.py collectstatic --noinput I'm getting the following error:

Post-processing 'jquery-ui-dist/jquery-ui.css' failed!
Traceback (most recent call last):
File "manage_local.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/michaelbates/GoogleDrive/Development/inl/venv/lib/python3.4/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/Users/michaelbates/GoogleDrive/Development/inl/venv/lib/python3.4/site-packages/django/core/management/__init__.py", line 359, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/michaelbates/GoogleDrive/Development/inl/venv/lib/python3.4/site-packages/django/core/management/base.py", line 294, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/michaelbates/GoogleDrive/Development/inl/venv/lib/python3.4/site-packages/django/core/management/base.py", line 345, in execute
output = self.handle(*args, **options)
File "/Users/michaelbates/GoogleDrive/Development/inl/venv/lib/python3.4/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 193, in handle
collected = self.collect()
File "/Users/michaelbates/GoogleDrive/Development/inl/venv/lib/python3.4/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 145, in collect
raise processed
File "/Users/michaelbates/GoogleDrive/Development/inl/venv/lib/python3.4/site-packages/django/contrib/staticfiles/storage.py", line 257, in post_process
content = pattern.sub(converter, content)
File "/Users/michaelbates/GoogleDrive/Development/inl/venv/lib/python3.4/site-packages/django/contrib/staticfiles/storage.py", line 187, in converter
hashed_url = self.url(unquote(target_name), force=True)
File "/Users/michaelbates/GoogleDrive/Development/inl/venv/lib/python3.4/site-packages/django/contrib/staticfiles/storage.py", line 132, in url
hashed_name = self.stored_name(clean_name)
File "/Users/michaelbates/GoogleDrive/Development/inl/venv/lib/python3.4/site-packages/django/contrib/staticfiles/storage.py", line 292, in stored_name
cache_name = self.clean_name(self.hashed_name(name))
File "/Users/michaelbates/GoogleDrive/Development/inl/venv/lib/python3.4/site-packages/django/contrib/staticfiles/storage.py", line 95, in hashed_name
(clean_name, self))
ValueError: The file 'jquery-ui-dist/"images/ui-icons_555555_256x240.png"' could not be found with <pipeline.storage.PipelineCachedStorage object at 0x1073e2c50>.

If I run python manage.py findstatic jquery-ui-dist/"images/ui-icons_555555_256x240.png" I get:

Found 'jquery-ui-dist/images/ui-icons_555555_256x240.png' here:
      /Users/michaelbates/GoogleDrive/Development/inl/node_modules/jquery-ui-dist/images/ui-icons_555555_256x240.png
      /Users/michaelbates/GoogleDrive/Development/inl/staticfiles/jquery-ui-dist/images/ui-icons_555555_256x240.png

Here are some relevant settings:

STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'pipeline.finders.AppDirectoriesFinder',
    'pipeline.finders.PipelineFinder',
)

STATICFILES_STORAGE = 'pipeline.storage.PipelineCachedStorage'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
    os.path.join(BASE_DIR, 'node_modules'),
)

My PIPELINE settings dict is huge so I won't post the entire thing, but some parts of it are:

PIPELINE = {
    'STYLESHEETS': {
        'pricing': {
            'source_filenames': (
                'jquery-ui-dist/jquery-ui.min.css',
            ),
            'output_filename': 'css/pricing.min.css'
        },
    }
    'JS_COMPRESSOR': 'pipeline.compressors.yuglify.YuglifyCompressor',
    'CSS_COMPRESSOR': 'pipeline.compressors.yuglify.YuglifyCompressor',
    'COMPILERS': (
        'pipeline.compilers.sass.SASSCompiler',
    )
}

I've tried changing the STATICFILES_FINDERS to the django-pipeline specific ones but it makes no difference.

Can anyone shed some light on why that png file can't be found during collectstatic but can with findstatic?

Upvotes: 3

Views: 2754

Answers (3)

Mr Coolman
Mr Coolman

Reputation: 25

This error is caused when you are trying to point to a static file which is invalid in your CSS property:

body {
   background-image: url(path/to/image/invalid_image.jpg);
}

Therefore all you need to do to get the error disappear for good is to ensure that you are pointing to the correct static file path.

More info? what happens in the background of this code block is that the url property expects a valid parameter which when it does find return None thus raising the exception because it can't store a None type value in the static file storage that you set in your django settings file.

Upvotes: 0

hn_tired
hn_tired

Reputation: 942

You can use the flag --no-post-process:

manage.py collectstatic --no-post-process

Upvotes: 3

Marcio Tomiyoshi
Marcio Tomiyoshi

Reputation: 106

Your problem is related to this bug on the Django project.

In short, django-pipeline is post-processing the url() calls with Django's CachedStaticFilesStorage to append the md5 checksum to the filename (more details here) and doesn't detect when it is inside a comment.

If you look on the header of the jquery-ui.css (and similar) files there is a comment that starts with

  • To view and modify this theme, visit [...]

Inside the URL on this line there is a parameter that is being interpreted as an url() call and generating the error you see.

To work around this issue you can simply remove the above line from jquery-ui.css and collectstatic should work properly.

Upvotes: 9

Related Questions