Depending on the material you're using, it says to install and use whitenoise as a package needed to run the Django app.
I would like to write about the error that occurred at that time.
Older materials are written to add the following to wsgi.py:
wsgi.py
from whitenoise.django import DjangoWhiteNoise
application = DjangoWhiteNoise(application)
And when I try to launch the app I get an error like this
ImportError:
Your WhiteNoise configuration is incompatible with WhiteNoise v4.0
This can be fixed by following the upgrade instructions at:
http://whitenoise.evans.io/en/stable/changelog.html#v4-0
http://whitenoise.evans.io/en/stable/changelog.html#v4-0
The latest version in January 2020 is whitenoise 5.0, and it seems that the notation to enable White Noise in Django has changed from version whitenoise 4.0.
Add the following sentence exactly as it is written.
settings.py
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
# ...
]
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
The caveat is to add it to the top of the middleware list.
And let's delete the part added to wsgi.py.
wsgi.py
from whitenoise.django import DjangoWhiteNoise #Delete this line
application = DjangoWhiteNoise(application) #Delete this line
Now it works fine.
Recommended Posts