【问题标题】:django-pipeline throwing ValueError: the file could not be founddjango-pipeline 抛出 ValueError:找不到文件
【发布时间】:2017-02-21 22:20:12
【问题描述】:

运行python manage.py collectstatic --noinput 时出现以下错误:

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>.

如果我运行python manage.py findstatic jquery-ui-dist/"images/ui-icons_555555_256x240.png",我会得到:

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

以下是一些相关设置:

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'),
)

我的PIPELINE 设置字典很大,所以我不会发布整个内容,但其中的某些部分是:

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',
    )
}

我尝试将 STATICFILES_FINDERS 更改为 django-pipeline 特定的,但没有任何区别。

谁能解释一下为什么在 collectstatic 期间找不到该 png 文件但使用 findstatic 可以找到该文件?

【问题讨论】:

    标签: python django asset-pipeline django-pipeline


    【解决方案1】:

    您的问题与 Django 项目中的this bug 有关。

    简而言之,django-pipeline 正在使用 Django 的 CachedStaticFilesStorageurl() 调用进行后处理,以将 md5 校验和附加到文件名 (more details here) 中,并且不检测它何时在评论中。

    如果您查看 jquery-ui.css(和类似)文件的标题,则会有以

    开头的注释
    • 要查看和修改此主题,请访问 [...]

    在这一行的 URL 中,有一个参数被解释为 url() 调用并生成您看到的错误。

    要解决此问题,您只需从jquery-ui.css 中删除上述行,collectstatic 应该可以正常工作。

    【讨论】:

    • 谢谢,这正是我的问题。大约一周前我意识到了这一点,但一直没有时间写下这个问题的答案。我会接受你的。
    • 这让我能够解决我无法识别的问题。谢谢。
    【解决方案2】:

    正如Marcio 所说,您可以从css 文件中删除url 或使用标志--no-post-process

    manage.py collectstatic --no-post-process
    

    【讨论】:

      猜你喜欢
      • 2012-08-02
      • 1970-01-01
      • 2013-04-28
      • 1970-01-01
      • 1970-01-01
      • 2018-04-24
      • 1970-01-01
      • 2016-11-13
      • 1970-01-01
      相关资源
      最近更新 更多