'collectstatic' command fails when WhiteNo

2020-02-03 05:13发布

I'm trying to serve static files through WhiteNoise as per Heroku's recommendation. When I run collectstatic in my development environment, this happens:

Post-processing 'css/iconic/open-iconic-bootstrap.css' failed!

Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/Pieter/.virtualenvs/radiant/lib/python3.4/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
    utility.execute()
  File "/home/Pieter/.virtualenvs/radiant/lib/python3.4/site-packages/django/core/management/__init__.py", line 377, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/Pieter/.virtualenvs/radiant/lib/python3.4/site-packages/django/core/management/base.py", line 288, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/home/Pieter/.virtualenvs/radiant/lib/python3.4/site-packages/django/core/management/base.py", line 338, in execute
    output = self.handle(*args, **options)
  File "/home/Pieter/.virtualenvs/radiant/lib/python3.4/site-packages/django/core/management/base.py", line 533, in handle
    return self.handle_noargs(**options)
  File "/home/Pieter/.virtualenvs/radiant/lib/python3.4/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 168, in handle_noargs
    collected = self.collect()
  File "/home/Pieter/.virtualenvs/radiant/lib/python3.4/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 120, in collect
    raise processed
  File "/home/Pieter/.virtualenvs/radiant/lib/python3.4/site-packages/django/contrib/staticfiles/storage.py", line 242, in post_process
    content = pattern.sub(converter, content)
  File "/home/Pieter/.virtualenvs/radiant/lib/python3.4/site-packages/django/contrib/staticfiles/storage.py", line 181, in converter
    hashed_url = self.url(unquote(joined_result), force=True)
  File "/home/Pieter/.virtualenvs/radiant/lib/python3.4/site-packages/django/contrib/staticfiles/storage.py", line 128, in url
    hashed_name = self.stored_name(clean_name)
  File "/home/Pieter/.virtualenvs/radiant/lib/python3.4/site-packages/django/contrib/staticfiles/storage.py", line 277, in stored_name
    cache_name = self.clean_name(self.hashed_name(name))
  File "/home/Pieter/.virtualenvs/radiant/lib/python3.4/site-packages/django/contrib/staticfiles/storage.py", line 91, in hashed_name
    (clean_name, self))
ValueError: The file 'css/fonts/open-iconic.eot' could not be found with <whitenoise.django.GzipManifestStaticFilesStorage object at 0x7f57fc5b1550>.

The static collection command runs without incident when I comment out this line in my settings:

STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'

What's going wrong here and how do I fix it? I already tried emptying my static file output folder. It runs smoothly until it starts processing one specific file.

11条回答
疯言疯语
2楼-- · 2020-02-03 05:46

I've had this error claiming a missing .css file when all my .css files existed, because I trusted Heroku documentation:

STATIC_ROOT = 'staticfiles'

over WhiteNoise documentation:

STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')

The fix is trivial, but until Heroku fix their docs (I submitted feedback), lets make sure the solution at least appears in SO.

查看更多
不美不萌又怎样
3楼-- · 2020-02-03 05:52

For me the fix was simply adding a 'static' folder to the top directory (myapp/static did the trick). If you are setting the STATIC_URL but don't have that directory already created, it will throw an error, even though you aren't using that directory for your static files with whitenoise.

STATIC_URL = '/static/'
查看更多
ゆ 、 Hurt°
4楼-- · 2020-02-03 05:53

I had similar problem, but with a twist.

I deployed on pythonanywhere. If I turn debug True, app runs fine. But if a turn debug False, app crashes with a error that with one line being the summary

ValueError: Missing staticfiles manifest entry for 'favicons/favicon.ico'

I changed from STATIC_ROOT = 'staticfiles to STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')

Deleted staticfiles directory, then rerun python manage.py collectstatic.

Now app runs fine

查看更多
【Aperson】
5楼-- · 2020-02-03 05:56

I just had this same issue and fixed it by removing this line from my settings file,

STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'

I got this line from the Heroku documentation page...

查看更多
\"骚年 ilove
6楼-- · 2020-02-03 06:00

Much like everyone else, I had a unique fix to this problem... turns out I had a url() in my styles.css file with bad syntax.

Once I changed:

background-image: url( '../images/futura_front_blank_medium.jpg' );

to

background-image: url('../images/futura_front_blank_medium.jpg');

(notice the subtle difference -- I removed the spaces on either side of the string)

then python manage.py collectstatic worked fine and I didn't get that error.

查看更多
男人必须洒脱
7楼-- · 2020-02-03 06:01

I've been dealing with this issue all day. It turns out the problem was the staticfiles directory was not checked in to git. I created a dummy file inside this directory, checked it in and everything was fine. This was mentioned somewhere in the Whitenoise documentation too, I believe.

查看更多
登录 后发表回答