Reputation: 1
I have a django app and I have the module: django-storages[azure] installed with the command: pip install django-storages[azure]
And now I try to run the collectstatic command. But if I enter the command: python manage.py collectstatic
I get this error:
File "C:\Users\USER\Desktop\Riley\lost-and-found-system\shadow\Lib\site-packages\django\core\files\storage\handler.py", line 35, in __getitem__
return self._storages[alias]
~~~~~~~~~~~~~~^^^^^^^
KeyError: 'staticfiles'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\USER\Desktop\Riley\lost-and-found-system\shadow\Lib\site-packages\django\core\files\storage\handler.py", line 52, in create_storage
storage_cls = import_string(backend)
^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\USER\Desktop\Riley\lost-and-found-system\shadow\Lib\site-packages\django\utils\module_loading.py", line 30, in import_string
return cached_import(module_path, class_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\USER\Desktop\Riley\lost-and-found-system\shadow\Lib\site-packages\django\utils\module_loading.py", line 15, in cached_import
module = import_module(module_path)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\USER\AppData\Local\Programs\Python\Python312\Lib\importlib\__init__.py", line 90, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen importlib._bootstrap>", line 1381, in _gcd_import
File "<frozen importlib._bootstrap>", line 1354, in _find_and_load
File "<frozen importlib._bootstrap>", line 1325, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 929, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 994, in exec_module
File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
File "C:\Users\USER\Desktop\Riley\lost-and-found-system\storages\backends\custom_azure.py", line 1, in <module>
from storages.backends.azure_storage import AzureStorage
ModuleNotFoundError: No module named 'storages.backends.azure_storage'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\USER\Desktop\Riley\lost-and-found-system\manage.py", line 22, in <module>
main()
File "C:\Users\USER\Desktop\Riley\lost-and-found-system\manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\Users\USER\Desktop\Riley\lost-and-found-system\shadow\Lib\site-packages\django\core\management\__init__.py", line 442, in execute_from_command_line
utility.execute()
File "C:\Users\USER\Desktop\Riley\lost-and-found-system\shadow\Lib\site-packages\django\core\management\__init__.py", line 436, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\USER\Desktop\Riley\lost-and-found-system\shadow\Lib\site-packages\django\core\management\base.py", line 412, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\USER\Desktop\Riley\lost-and-found-system\shadow\Lib\site-packages\django\core\management\base.py", line 458, in execute
output = self.handle(*args, **options)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\USER\Desktop\Riley\lost-and-found-system\shadow\Lib\site-packages\django\contrib\staticfiles\management\commands\collectstatic.py", line 184, in handle
if self.is_local_storage() and self.storage.location:
^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\USER\Desktop\Riley\lost-and-found-system\shadow\Lib\site-packages\django\contrib\staticfiles\management\commands\collectstatic.py", line 245, in is_local_storage
return isinstance(self.storage, FileSystemStorage)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\USER\Desktop\Riley\lost-and-found-system\shadow\Lib\site-packages\django\utils\functional.py", line 280, in __getattribute__
value = super().__getattribute__(name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\USER\Desktop\Riley\lost-and-found-system\shadow\Lib\site-packages\django\utils\functional.py", line 251, in inner
self._setup()
File "C:\Users\USER\Desktop\Riley\lost-and-found-system\shadow\Lib\site-packages\django\contrib\staticfiles\storage.py", line 540, in _setup
self._wrapped = storages[STATICFILES_STORAGE_ALIAS]
~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\USER\Desktop\Riley\lost-and-found-system\shadow\Lib\site-packages\django\core\files\storage\handler.py", line 43, in __getitem__
storage = self.create_storage(params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\USER\Desktop\Riley\lost-and-found-system\shadow\Lib\site-packages\django\core\files\storage\handler.py", line 54, in create_storage
raise InvalidStorageError(f"Could not find backend {backend!r}: {e}") from e
django.core.files.storage.handler.InvalidStorageError: Could not find backend 'storages.backends.custom_azure.AzureStaticStorage': No module named
'storages.backends.azure_storage'
i have checked the import paths and i can go to the definition of the classes in my editor
(shadow)
USER@DESKTOP-7TEEU5T MINGW64 ~/Desktop/Riley/lost-and-found-system
$ ls
findit/ manage.py* media/ README.md requirements.txt shadow/ static/ staticfiles/ storages/ Team1/
(shadow)
USER@DESKTOP-7TEEU5T MINGW64 ~/Desktop/Riley/lost-and-found-system
$ cd storages
(shadow)
USER@DESKTOP-7TEEU5T MINGW64 ~/Desktop/Riley/lost-and-found-system/storages
$ cd backends
(shadow)
USER@DESKTOP-7TEEU5T MINGW64 ~/Desktop/Riley/lost-and-found-system/storages/backends
$ ls
__init__.py __pycache__/ custom_azure.py
my settings.py file looks like
DEFAULT_FILE_STORAGE = 'storages.backends.custom_azure.AzureMediaStorage'
STATICFILES_STORAGE = 'storages.backends.custom_azure.AzureStaticStorage'
STATIC_LOCATION = 'static'
MEDIA_LOCATION = 'media'
STATIC_URL = f'https://{AZURE_CUSTOM_DOMAIN}/{STATIC_LOCATION}/'
MEDIA_URL = f'https://{AZURE_CUSTOM_DOMAIN}/{MEDIA_LOCATION}/'
and in my storages/backends/custom_azure.py file i have
from storages.backends.azure_storage import AzureStorage
class AzureMediaStorage(AzureStorage):
...
class AzureStaticStorage(AzureStorage):
...
Upvotes: 0
Views: 51