Fixed #26029 -- Allowed configuring custom file storage backends.

This commit is contained in:
Jarosław Wygoda 2023-01-11 10:48:57 +01:00 committed by Mariusz Felisiak
parent d02a9f0cee
commit 1ec3f0961f
12 changed files with 209 additions and 11 deletions

View file

@ -23,6 +23,7 @@ Settings
See :ref:`staticfiles settings <settings-staticfiles>` for details on the
following settings:
* :setting:`STORAGES`
* :setting:`STATIC_ROOT`
* :setting:`STATIC_URL`
* :setting:`STATICFILES_DIRS`

View file

@ -9,6 +9,12 @@ Getting the default storage class
Django provides convenient ways to access the default storage class:
.. data:: storages
.. versionadded:: 4.2
Storage instances as defined by :setting:`STORAGES`.
.. class:: DefaultStorage
:class:`~django.core.files.storage.DefaultStorage` provides

View file

@ -2606,6 +2606,43 @@ Silenced checks will not be output to the console.
See also the :doc:`/ref/checks` documentation.
.. setting:: STORAGES
``STORAGES``
------------
.. versionadded:: 4.2
Default::
{}
A dictionary containing the settings for all storages to be used with Django.
It is a nested dictionary whose contents map a storage alias to a dictionary
containing the options for an individual storage.
Storages can have any alias you choose.
The following is an example ``settings.py`` snippet defining a custom file
storage called ``example``::
STORAGES = {
# ...
"example": {
"BACKEND": "django.core.files.storage.FileSystemStorage",
"OPTIONS": {
"location": "/example",
"base_url": "/example/",
},
},
}
``OPTIONS`` are passed to the ``BACKEND`` on initialization in ``**kwargs``.
A ready-to-use instance of the storage backends can be retrieved from
:data:`django.core.files.storage.storages`. Use a key corresponding to the
backend definition in :setting:`STORAGES`.
.. setting:: TEMPLATES
``TEMPLATES``
@ -3663,6 +3700,7 @@ File uploads
* :setting:`FILE_UPLOAD_TEMP_DIR`
* :setting:`MEDIA_ROOT`
* :setting:`MEDIA_URL`
* :setting:`STORAGES`
Forms
-----