Skip to content

Commit

Permalink
[docs] fix STORAGES settings in docs for Django 4.2 (#1229)
Browse files Browse the repository at this point in the history
* Update README.rst

Fix settings for Django 4.2

* Squashed commit of the following:

commit 12c43fc
Author: Phil Gyford <phil@gyford.com>
Date:   Wed Apr 5 15:31:33 2023 +0100

    Update gcloud.rst

    Fix settings for Django 4.2

* Squashed commit of the following:

commit 3afd2c1
Author: Phil Gyford <phil@gyford.com>
Date:   Wed Apr 5 15:30:51 2023 +0100

    Update ftp.rst

    Fix settings for Django 4.2

* Squashed commit of the following:

commit c35bd95
Author: Phil Gyford <phil@gyford.com>
Date:   Wed Apr 5 15:30:21 2023 +0100

    Update dropbox.rst

    Fix settings for Django 4.2

* Squashed commit of the following:

commit 05910cb
Author: Phil Gyford <phil@gyford.com>
Date:   Wed Apr 5 15:29:46 2023 +0100

    Update azure.rst

    Fix settings for Django 4.2

* Squashed commit of the following:

commit 1eccb73
Author: Phil Gyford <phil@gyford.com>
Date:   Wed Apr 5 15:27:50 2023 +0100

    Update apache_libcloud.rst

    Fix settings for Django 4.2

* Squashed commit of the following:

commit 7aea7be
Author: Phil Gyford <phil@gyford.com>
Date:   Wed Apr 5 15:26:58 2023 +0100

    Update amazon-S3.rst

    Fix settings for Django 4.2
  • Loading branch information
philgyford committed Apr 14, 2023
1 parent 90e2e78 commit 8025ece
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 11 deletions.
16 changes: 15 additions & 1 deletion README.rst
Expand Up @@ -25,13 +25,27 @@ hasn't been released yet) then the magic incantation you are looking for is:
pip install -e 'git+https://github.com/jschneier/django-storages.git#egg=django-storages'
Once that is done set ``DEFAULT_FILE_STORAGE`` to the backend of your choice.
Once that is done, if using Django 4.1 or earlier, set ``DEFAULT_FILE_STORAGE`` to the backend of your choice.
If, for example, you want to use the boto3 backend you would set:

.. code-block:: python
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
For Django 4.2 or later, set the ``default`` value in ``STORAGES`` to the backend of your choice. For example:

.. code-block:: python
STORAGES = {
'default': {
'BACKEND': 'storages.backends.s3boto3.S3Boto3Storage',
},
'staticfiles': {
# Leave whatever setting you already have here, e.g.:
'BACKEND': 'django.contrib.staticfiles.storage.StaticFilesStorage',
}
}
If you are using the ``FileSystemStorage`` as your storage management class in your models ``FileField`` fields, remove them
and don't specify any storage parameter. That way, the ``DEFAULT_FILE_STORAGE`` class will be used by default in your field.
Expand Down
6 changes: 3 additions & 3 deletions docs/backends/amazon-S3.rst
Expand Up @@ -19,7 +19,7 @@ To upload your media files to S3 set::
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'

# django >= 4.2
STORAGES = {"default": "storages.backends.s3boto3.S3Boto3Storage"}
STORAGES = {"default": {"BACKEND": "storages.backends.s3boto3.S3Boto3Storage"}}


To allow ``django-admin collectstatic`` to automatically put your static files in your bucket set the following in your settings.py::
Expand All @@ -28,15 +28,15 @@ To allow ``django-admin collectstatic`` to automatically put your static files i
STATICFILES_STORAGE = 'storages.backends.s3boto3.S3StaticStorage'

# django >= 4.2
STORAGES = {"staticfiles": "storages.backends.s3boto3.S3StaticStorage"}
STORAGES = {"staticfiles": {"BACKEND": "storages.backends.s3boto3.S3StaticStorage"}}

If you want to use something like `ManifestStaticFilesStorage`_ then you must instead use::

# django < 4.2
STATICFILES_STORAGE = 'storages.backends.s3boto3.S3ManifestStaticStorage'

# django >= 4.2
STORAGES = {"staticfiles": "storages.backends.s3boto3.S3ManifestStaticStorage"}
STORAGES = {"staticfiles": {"BACKEND": "storages.backends.s3boto3.S3ManifestStaticStorage"}}

There are several different methods for specifying the AWS credentials used to create the S3 client. In the order that ``S3Boto3Storage``
searches for them:
Expand Down
2 changes: 1 addition & 1 deletion docs/backends/apache_libcloud.rst
Expand Up @@ -153,7 +153,7 @@ set::
DEFAULT_FILE_STORAGE = 'storages.backends.apache_libcloud.LibCloudStorage'

# django >= 4.2
STORAGES = {"default": "storages.backends.apache_libcloud.LibCloudStorage"}
STORAGES = {"default": {"BACKEND": "storages.backends.apache_libcloud.LibCloudStorage"}}

Your default Libcloud provider will be used as the file store.

Expand Down
11 changes: 9 additions & 2 deletions docs/backends/azure.rst
Expand Up @@ -64,8 +64,8 @@ Then on settings set::

# django >= 4.2
STORAGES = {
"default": "storages.backends.azure_storage.AzureStorage",
"staticfiles": "custom_storage.custom_azure.PublicAzureStorage",
"default": {"BACKEND": "storages.backends.azure_storage.AzureStorage"},
"staticfiles": {"BACKEND": "custom_storage.custom_azure.PublicAzureStorage"},
}

+++++++++++++++++++++
Expand Down Expand Up @@ -93,9 +93,16 @@ configuration file, usually `settings.py`.
Set the default storage (i.e: for media files) and the static storage
(i.e: fo static files) to use the azure backend::

# django < 4.2
DEFAULT_FILE_STORAGE = 'storages.backends.azure_storage.AzureStorage'
STATICFILES_STORAGE = 'storages.backends.azure_storage.AzureStorage'

# django >= 4.2
STORAGES = {
"default": {"BACKEND": "storages.backends.azure_storage.AzureStorage"},
"staticfiles": {"BACKEND": "storages.backends.azure_storage.AzureStorage"},
}

The following settings are available:

``AZURE_ACCOUNT_NAME``
Expand Down
2 changes: 1 addition & 1 deletion docs/backends/dropbox.rst
Expand Up @@ -18,7 +18,7 @@ To use DropBoxStorage set::
DEFAULT_FILE_STORAGE = 'storages.backends.dropbox.DropBoxStorage'

# django >= 4.2
STORAGES = {"default": "storages.backends.dropbox.DropBoxStorage"}
STORAGES = {"default": {"BACKEND": "storages.backends.dropbox.DropBoxStorage"}}

Two methods of authenticating are supported:

Expand Down
2 changes: 1 addition & 1 deletion docs/backends/ftp.rst
Expand Up @@ -14,7 +14,7 @@ To use FtpStorage set::
DEFAULT_FILE_STORAGE = 'storages.backends.ftp.FTPStorage'

# django >= 4.2
STORAGES = {"default": "storages.backends.ftp.FTPStorage"}
STORAGES = {"default": {"BACKEND": "storages.backends.ftp.FTPStorage"}}

``FTP_STORAGE_LOCATION``
URL of the server that holds the files. Example ``'ftp://<user>:<pass>@<host>:<port>'``
Expand Down
4 changes: 2 additions & 2 deletions docs/backends/gcloud.rst
Expand Up @@ -46,7 +46,7 @@ Set the default storage and bucket name in your settings.py file
DEFAULT_FILE_STORAGE = 'storages.backends.gcloud.GoogleCloudStorage'
# django >= 4.2
STORAGES = {"default": "storages.backends.gcloud.GoogleCloudStorage"}
STORAGES = {"default": {"BACKEND": "storages.backends.gcloud.GoogleCloudStorage"}}
GS_BUCKET_NAME = 'YOUR_BUCKET_NAME_GOES_HERE'
Expand All @@ -57,7 +57,7 @@ To allow ``django-admin`` collectstatic to automatically put your static files i
STATICFILES_STORAGE = 'storages.backends.gcloud.GoogleCloudStorage'

# django >= 4.2
STORAGES = {"staticfiles": "storages.backends.gcloud.GoogleCloudStorage"}
STORAGES = {"staticfiles": {"BACKEND": "storages.backends.gcloud.GoogleCloudStorage"}}

Once you're done, default_storage will be Google Cloud Storage

Expand Down

0 comments on commit 8025ece

Please sign in to comment.