'collectstatic' command fails when WhiteNoise is enabled
Asked Answered
G

16

32

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.

Girand answered 9/11, 2014 at 14:50 Comment(0)
R
20

The problem here is that css/iconic/open-iconic-bootstrap.css is referencing a file, open-iconic.eot, which doesn't exist in the expected location.

When you run collectstatic with that storage backend Django attempts to rewrite all the URLs in your CSS files so they reference the files by their new names e.g, css/iconic/open-iconic.8a7442ca6bed.eot. If it can't find the file it stops with that error.

Rozele answered 13/11, 2014 at 11:47 Comment(6)
Is this behavior specific to WhiteNoise? Because I don't experience the issue if I have WhiteNoise disabled. I checked open-iconic-bootstrap.css and there's no difference between the original file and the copy in the static folder.Girand
No it's not WhiteNoise specific: you'll find you get it if you use django.contrib.staticfiles.storage.CachedStaticFilesStorage as well. You don't have to use the storage backend to use WhiteNoise, it just gets you better performance.Rozele
The storage backend is only complaining because your .eot font file is missing, so you'll find your icon fonts won't be working in Internet Explorer. If you fix that then collectstatic should run without problem.Rozele
You were right, thanks for helping me understand what was going on!Girand
Thanks for explaining. But still, do you know any way to fix it ? While obviously still using WhiteNoise.Undermost
The fix is either to remove the line in the CSS which references the missing file, or to copy the file into the right place so it's no longer missing.Rozele
K
21

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

Kila answered 2/9, 2015 at 7:44 Comment(5)
I don't know but this worked for me. Anyone know the repercussions?Helotism
I had the same issue, removing GzipManifestStaticFilesStore worked for me too, but it must be another workaround, I want to use file compression.Kamat
@BernardParah you're disabling the compression and caching support from whitenoise. You don't need it to use whitenoise, but it is nice.Flaring
This worked for me as i was using cloudinary which caused issues. Thanks as this was causing me a headache :)Quisling
Hi guys, I have same problem. But in my case I have wrong reference to jquery, I have there extra slash on begining of the path: # this is wrong, path starts with "/admin" <script type="text/javascript" src="{% static "admin/js/vendor/jquery/jquery.js" %}"></script> # this is ok, path starts with "admin" <script type="text/javascript" src="{% static "admin/js/vendor/jquery/jquery.js" %}"></script> ```Ritz
R
20

The problem here is that css/iconic/open-iconic-bootstrap.css is referencing a file, open-iconic.eot, which doesn't exist in the expected location.

When you run collectstatic with that storage backend Django attempts to rewrite all the URLs in your CSS files so they reference the files by their new names e.g, css/iconic/open-iconic.8a7442ca6bed.eot. If it can't find the file it stops with that error.

Rozele answered 13/11, 2014 at 11:47 Comment(6)
Is this behavior specific to WhiteNoise? Because I don't experience the issue if I have WhiteNoise disabled. I checked open-iconic-bootstrap.css and there's no difference between the original file and the copy in the static folder.Girand
No it's not WhiteNoise specific: you'll find you get it if you use django.contrib.staticfiles.storage.CachedStaticFilesStorage as well. You don't have to use the storage backend to use WhiteNoise, it just gets you better performance.Rozele
The storage backend is only complaining because your .eot font file is missing, so you'll find your icon fonts won't be working in Internet Explorer. If you fix that then collectstatic should run without problem.Rozele
You were right, thanks for helping me understand what was going on!Girand
Thanks for explaining. But still, do you know any way to fix it ? While obviously still using WhiteNoise.Undermost
The fix is either to remove the line in the CSS which references the missing file, or to copy the file into the right place so it's no longer missing.Rozele
O
12

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.

Oblong answered 21/2, 2015 at 2:40 Comment(1)
This turned out to fix my problem with Heroku and static files when using WhiteNoise. Thanks!Ouster
H
8

In newer versions of whitenoise there are only two storage classes available:

  • whitenoise.storage.CompressedManifestStaticFilesStorage
  • whitenoise.storage.CompressedStaticFilesStorage

This error will arise with CompressedManifestStaticFilesStorage, in cases where any of your static assets refer to other assets that cannot be found by the staticfiles finder. This is because the HashedFilesMixin parses all the files to find references to other assets, so that it can pregenerate hashes for all of them to add to the manifest.

There are two ways to resolve this:

  1. Switch to using CompressedStaticFilesStorage (no Manifest), so that file hashes are not pre-rendered.

  2. Identify all the missing files reported during collectstatic and either ensure that they are present in your collected directories, or remove references to them in your static files.

Hour answered 31/3, 2022 at 4:29 Comment(3)
It does not make sense to remove whitenoise from your cool app. This answer was the only solution that worked for me among many not relevant ones.Intercession
This worked for me, thanks so much for relieving me of this headache, now I can sleep in peace! Your head is blessed with more knowledge, amen! Idk why and idc to be honest.Edan
This answer solved my problem for built files generated by vite/webpack and output into static folders for use in Django appSemidiurnal
W
3

The issue here is that using

STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

or

STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.ManifestStaticFilesStorage

uses Django's static file storage in a different way than runserver does. See the Django docs for some explanation: https://docs.djangoproject.com/en/1.11/ref/contrib/staticfiles/#django.contrib.staticfiles.storage.ManifestStaticFilesStorage.manifest_strict

I believe the referenced manifest gets built when you run collectstatic, so doing so should fix this problem temporarily, but you likely don't want to run collectstatic before every test run if you have modified any static files. Another solution would be to disable this setting for your tests, and just run it in production.

William answered 8/9, 2017 at 18:50 Comment(0)
B
2

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

Beltane answered 2/2, 2018 at 12:49 Comment(0)
S
2

In development Django’s runserver automatically takes over static file handling.

In most cases this is fine, however this means that some of the improvements that WhiteNoise makes to static file handling won’t be available in development and it opens up the possibility for differences in behaviour between development and production environments. For this reason it’s a good idea to use WhiteNoise in development as well.

You can disable Django’s static file handling and allow WhiteNoise to take over simply by passing the --nostatic option to the runserver command, but you need to remember to add this option every time you call runserver. An easier way is to edit your settings.py file and add whitenoise.runserver_nostatic to the top of your INSTALLED_APPS list:

INSTALLED_APPS = [
'whitenoise.runserver_nostatic',
'django.contrib.staticfiles',
# ...]

Source - http://whitenoise.evans.io/en/stable/django.html#using-whitenoise-in-development

Scissel answered 28/8, 2020 at 15:13 Comment(0)
P
1

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/'
Pow answered 28/5, 2017 at 22:43 Comment(0)
K
1

There are two options:

  1. To add the proper link which is in css
  2. By removing the link of file which is not present from css
Karyoplasm answered 20/4, 2020 at 19:58 Comment(0)
P
0

It worked for me by commenting out the whitenoise in settings.py in production.

#STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'
#WHITENOISE_ROOT = os.path.join(BASE_DIR, 'staticfiles')
Pyuria answered 23/9, 2017 at 20:13 Comment(1)
This does work, but now you are no longer using whitenoise so you should remove the app completelyMiskolc
T
0

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.

Teat answered 2/8, 2018 at 1:32 Comment(0)
H
0

Be sure to check all your settings related to static files, especially making sure the paths are pointing to the right locations. I personally had one of my STATICFILES_DIRS pointing to a wrong path.

Headland answered 29/12, 2018 at 0:22 Comment(0)
T
0

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.

Tyrannosaur answered 4/4, 2019 at 19:6 Comment(0)
C
0

The whitenoise.django.GzipManifestStaticFilesStorage alias has now been removed. Instead you should use the correct import path: whitenoise.storage.CompressedManifestStaticFilesStorage.

As per the doc here.

Casuistry answered 5/4, 2019 at 18:19 Comment(0)
C
0

In my case there was another solution. In Heroku config I had a setting:

DISABLE_COLLECTSTATIC=0

which should let Heroku collect static automaticly by pushing to heroku master, but it didn`t!.

What I did was removing this setting on

Heroku > my_app > settings > config vars

and after that Heroku collected staticfiles automaticly and problem dissappeard.

Circulate answered 3/4, 2020 at 11:54 Comment(0)
W
0

I didn't face this issue until building my project's docker image on Linux. I usually build on macOS.

I believe there is a difference in case sensitivity by default between the most common filesystems used by these two OSes.

I solved this issue by renaming the files linked from my CSS to all lowercase.

Previously:

url('/static/Some-File.png')

Now:

url('/static/some-file.png')
Wither answered 27/9, 2022 at 21:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.