[PYTHON] How to deal with errors when installing whitenoise and deploying to Heroku

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

How to deal with errors when installing whitenoise and deploying to Heroku
How to deal with errors when installing Python and pip with choco
How to deal with errors when hitting pip ②
How to deal with DistributionNotFound errors
How to deal with enum compatibility errors
[Python] How to deal with module errors
How to deal with run-time errors in subprocess.call
How to deal with SessionNotCreatedException when using Selenium
[Linux] How to deal with garbled characters when viewing files
For beginners, how to deal with common errors in keras
How to deal with UnicodeDecodeError when executing google image download
How to deal with imbalanced data
How to deal with imbalanced data
How to install pandas on EC2 (How to deal with MemoryError and PermissionError)
How to deal with OAuth2 error when using Google APIs from Python
How to deal with SSL error when connecting to S3 with boto of Python
[AWS] How to deal with WordPress "An error occurred when cropping an image."
How to upload with Heroku, Flask, Python, Git (4)
How to deal with memory leaks in matplotlib.pyplot
can't pickle annoy. How to deal with Annoy objects
How to deal with module'tensorflow' has no attribute'〇〇'
[EC2] How to deal with errors that selenium cannot execute (No module named selenium)
To avoid seeing hell when installing django-toolbelt on windows, heroku and python3.4 (64bit) ...
How to upload with Heroku, Flask, Python, Git (Part 3)
How to deal with Django's Template Does Not Exist
How to deal with pyenv initialization failure in fish 3.1.0
How to share folders with Docker and Windows with tensorflow
How to access with cache when reading_json in pandas
How to extract null values and non-null values with pandas
How to deal with "Type Error: No matching signature found" error when using pandas fillna
How to upload with Heroku, Flask, Python, Git (Part 1)
[Python] How to deal with pandas read_html read error
How to loop and play gif video with openCV
How to make an arbitrary DictCursor with PyMySQL and not return None when NULL
How to upload with Heroku, Flask, Python, Git (Part 2)
How to change the behavior when loading / dumping yaml with PyYAML and its details
How to deal with Executing transaction: failed in Anaconda
[How to!] Learn and play Super Mario with Tensorflow !!
Template for Bottle when deploying with Github and Bitbucket
How to deal with "fatal: destination path''already exists and is not an empty directory." When trying to clone on Git hub
How to deal with the terminal getting into the pipenv environment without permission when using pipenv with vscode
How to deploy a web app made with Flask to Heroku
When I try to push with heroku, it doesn't work
How to not load images when using PhantomJS with Selenium
How to resolve CSRF Protection when using AngularJS with Django
How to do Bulk Update with PyMySQL and notes [Python]
What to do if package installation fails when deploying to heroku
[AWS] How to deal with "Invalid codepoint" error in CloudSearch
A story about how to deal with the CORS problem
How to create dataframes and mess with elements in pandas
How to output additional information when logging with python's logging module
How to log in to AtCoder with Python and submit automatically
How to update with SQLAlchemy?
How to cast with Theano
How to Alter with SQLAlchemy?
How to separate strings with','
How to RDP with Fedora31
2 ways to deal with SessionNotCreatedException
How to Delete with SQLAlchemy?
How to deal with the problem that the current directory moves when Python is executed from Atom
How to deal with the error "Failed to load module" canberra-gtk-module "that appears when you run OpenCV