Search code examples
pythondjangoheroku

Tried using white noise and got the following "error ImportError: No module named 'whitenoise.middleware' "


I tried to follow the whitenoise instruction. I installed it from my requirements.txt the following are the versions I'm using

whitenoise==2.0.6
Django==1.9.2

then I installed it in my settings.py middleware like the instructions say

'whitenoise.middleware.WhiteNoiseMiddleware',

this caused a system interrupt when I did this. When I went to local host I got the following error

A server error occurred.  Please contact the administrator.

When I googled I only saw one other intance of the problem I had. It was on github and they suggested 'Use the documentation on ReadTheDocs, github is where development happens and the docs there refer to the unreleased version.'

How can I fix this? all guidance is welcome

EDIT Traceback

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/wsgiref/handlers.py", line 137, in run
    self.result = application(self.environ, self.start_response)
  File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/django/contrib/staticfiles/handlers.py", line 63, in __call__
    return self.application(environ, start_response)
  File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/whitenoise/base.py", line 119, in __call__
    return self.application(environ, start_response)
  File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/django/core/handlers/wsgi.py", line 158, in __call__
    self.load_middleware()
  File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/django/core/handlers/base.py", line 51, in load_middleware
    mw_class = import_string(middleware_path)
  File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/django/utils/module_loading.py", line 20, in import_string
    module = import_module(module_path)
  File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 956, in _find_and_load_unlocked
ImportError: No module named 'whitenoise.middleware'
[05/Apr/2016 17:23:01] "GET / HTTP/1.1" 500 59

Solution

  • whitenoise middleware is new in version 3.0, but you have installed 2.0.6.

    Either upgrade your installation or follow the version 2 docs instead.