How to Solve Error Message ImportError: Your WhiteNoise configuration is incompatible with WhiteNoise v4.0 when executing python manage.py collectstatic

Posted on

This article is actually a continuation from the previous article. It is an event where the solution in the previous article with the title of ‘How to Solve error Message ModuleNotFoundError : No module named ‘whitenoise’ when executing python manage.py collectstatic’ in this link. The problem continue by displaying a different type of error. The error itself exist in the title of the article. The main cause is the definition of the following line configuration in the ‘settings.py’ file in a Django-based framework web application :

STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'

Below is the full output error message describing it :

(env) user@hostname:~/python/django/todoproject$ python manage.py collectstatic
Traceback (most recent call last):
  File "manage.py", line 21, in 
    main()
  File "manage.py", line 17, in main
    execute_from_command_line(sys.argv)
  File "/home/user/python/django/env/lib/python3.7/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "/home/user/python/django/env/lib/python3.7/site-packages/django/core/management/__init__.py", line 375, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/user/python/django/env/lib/python3.7/site-packages/django/core/management/base.py", line 323, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/user/python/django/env/lib/python3.7/site-packages/django/core/management/base.py", line 364, in execute
    output = self.handle(*args, **options)
  File "/home/user/python/django/env/lib/python3.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 162, in handle
    if self.is_local_storage() and self.storage.location:
  File "/home/user/python/django/env/lib/python3.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 216, in is_local_storage
    return isinstance(self.storage, FileSystemStorage)
  File "/home/user/python/django/env/lib/python3.7/site-packages/django/utils/functional.py", line 256, in inner
    self._setup()
  File "/home/user/python/django/env/lib/python3.7/site-packages/django/contrib/staticfiles/storage.py", line 498, in _setup
    self._wrapped = get_storage_class(settings.STATICFILES_STORAGE)()
  File "/home/user/python/django/env/lib/python3.7/site-packages/django/core/files/storage.py", line 358, in get_storage_class
    return import_string(import_path or settings.DEFAULT_FILE_STORAGE)
  File "/home/user/python/django/env/lib/python3.7/site-packages/django/utils/module_loading.py", line 17, in import_string
    module = import_module(module_path)
  File "/home/user/python/django/env/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "", line 1006, in _gcd_import
  File "", line 983, in _find_and_load
  File "", line 967, in _find_and_load_unlocked
  File "", line 677, in _load_unlocked
  File "", line 728, in exec_module
  File "", line 219, in _call_with_frames_removed
  File "/home/user/python/django/env/lib/python3.7/site-packages/whitenoise/django.py", line 2, in 
    "\n\n"
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

So, the following is the solution taken to solve the above problem or error message :

1. According to the link above, the following step is just to install the different version of the module or to upgrade it according to information on the link. The following is the execution of the process :

(env) user@hostname:~/python/django/todoproject$ pip install whitenoise[brotli]
Requirement already satisfied: whitenoise[brotli] in /home/user/python/django/env/lib/python3.7/site-packages (5.0.1)
Collecting Brotli; extra == "brotli"
  Downloading Brotli-1.0.7-cp37-cp37m-manylinux1_x86_64.whl (352 kB)
     |████████████████████████████████| 352 kB 248 kB/s 
Installing collected packages: Brotli
Successfully installed Brotli-1.0.7
(env) user@hostname:~/python/django/todoproject$ 

2. Unfortunately, the solution is not a success. The above alternative solution step is still not working.

Finally, the solution is just remove the definition of the above configuration in the ‘settings.py’ file. Just remove the following line configuration or give a remark or comment sign in the ‘settings.py’ file :

# STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'

 

Continue on the process, collecting static files can still be a success without the above line configuration. The following is the actual execution after removing or commenting the above line configuration :

(env) user@hostname:~/python/django/todoproject$ python manage.py collectstatic
119 static files copied to '/home/user/python/django/todoproject/todoproject/static'.
(env) user@hostname:~/python/django/todoproject$ python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
March 15, 2020 - 09:07:23
Django version 2.2.6, using settings 'todoproject.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

Leave a Reply