Reputation: 53
I'm using Docker to deploy my application and for some reason every time my Django server keeps returning the following error: ImportError: No module named 'whitenoise'
, even though it says that the module is already installed: Requirement already satisfied: whitenoise in /usr/local/lib/python3.5/dist-packages (3.3.1)
.
Any help on this issue is greatly appreciated.
Upvotes: 1
Views: 32768
Reputation: 491
for those have already installed whitenoise using pip.
step - 1: check for the middlewares are added in settings.py
"django.middleware.security.SecurityMiddleware",
"whitenoise.middleware.WhiteNoiseMiddleware",
step - 2:
WhiteNoise comes with a storage backend which automatically takes care of compressing your files and creating unique names for each version so they can safely be cached forever. To use it, just add this to your settings.py:
STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"
or
This combines automatic compression with the caching behaviour provided by Django’s ManifestStaticFilesStorage backend. If you want to apply compression but don’t want the caching behaviour then you can use:
STATICFILES_STORAGE = "whitenoise.storage.CompressedStaticFilesStorage"
refer documentation: https://whitenoise.evans.io/en/stable/django.html
Upvotes: 5
Reputation: 55
if you use Django==2.0 and Python >=3.5, you should install whitenoise==3.3.1. So, in wsgi.py, you can use "application = DjangoWhiteNoise(application)".
Upvotes: 4
Reputation: 2223
You are installing at wrong place... probabily you are forgeting to create/install/activate your virtualenv in your docker container, so when you login it installed globaly and your code in trying to find at VM, or you installed in VM and your code is lookings globaly.
http://tinystruggles.com/2014/11/16/docker-virtualenv.html
Upvotes: 7