jschneier / django-storages

https://django-storages.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
2.7k stars 847 forks source link

Staticfiles STORAGES key attribute error #1409

Closed victorbmlabs closed 1 month ago

victorbmlabs commented 1 month ago

I'm trying to configure Django (5.0.4) to use Google Cloud S3 as my file storage using django-stores.

Here is what my settings.py configuration for object storage looks like:

from google.oauth2.service_account import Credentials

STORAGES = {
    "default": {
        "BACKEND": "storages.backends.gcloud.GoogleCloudStorage",
        "OPTIONS": {
            "GS_BUCKET_NAME": "BUCKET",
            "GS_PROJECT_ID": "PROJECT",
            "GS_CREDENTIALS": Credentials.from_service_account_file("service-account.json"),
        },
    },
    "staticfiles": "storages.backends.gcloud.GoogleCloudStorage"
}

After running python manage.py collectstatic I'm getting the following AttributeError

Traceback (most recent call last):
  File "/home/victor/BmLabs/site/manage.py", line 22, in <module>
    main()
  File "/home/victor/BmLabs/site/manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "/home/victor/.pyenv/versions/bmlabs/lib/python3.12/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
    utility.execute()
  File "/home/victor/.pyenv/versions/bmlabs/lib/python3.12/site-packages/django/core/management/__init__.py", line 382, in execute
    settings.INSTALLED_APPS
  File "/home/victor/.pyenv/versions/bmlabs/lib/python3.12/site-packages/django/conf/__init__.py", line 89, in __getattr__
    self._setup(name)
  File "/home/victor/.pyenv/versions/bmlabs/lib/python3.12/site-packages/django/conf/__init__.py", line 76, in _setup
    self._wrapped = Settings(settings_module)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/victor/.pyenv/versions/bmlabs/lib/python3.12/site-packages/django/conf/__init__.py", line 262, in __init__
    self.STORAGES.get(STATICFILES_STORAGE_ALIAS, {}).get("BACKEND"),
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'str' object has no attribute 'get'

As per the guide I've set the staticfiles key to storages.backends.gcloud.GoogleCloudStorage.