StorageHandler
This class manages a collection of storage backends, providing a centralized interface to access and instantiate storage instances based on configuration settings. It supports lazy loading and caching of storage objects, allowing users to retrieve specific backends by alias. The class handles the dynamic importation of backend classes and applies provided options during initialization.
Attributes
| Attribute | Type | Description |
|---|---|---|
| _backends | dict | Dictionary of storage backend definitions used to configure storage instances, typically structured like settings.STORAGES. |
| _storages | dict = {} | Internal cache that stores instantiated storage objects keyed by their alias to ensure singletons per alias. |
Constructor
Signature
def StorageHandler(
backends: dict = None
) - > null
Parameters
| Name | Type | Description |
|---|---|---|
| backends | dict = None | An optional dictionary of storage backend definitions, typically structured like settings.STORAGES. |
Methods
backends()
@classmethod
def backends() - > dict
Retrieves the dictionary of storage backend definitions, defaulting to the project's STORAGES setting if no specific backends were provided during initialization.
Returns
| Type | Description |
|---|---|
dict | A dictionary mapping storage aliases to their respective configuration parameters. |
create_storage()
@classmethod
def create_storage(
params: dict
) - > [Storage](../base/storage.md?sid=django_core_files_storage_base_storage)
Instantiates a new storage backend object using the provided configuration parameters.
Parameters
| Name | Type | Description |
|---|---|---|
| params | dict | A configuration dictionary containing the 'BACKEND' class path and an optional 'OPTIONS' dictionary for constructor arguments. |
Returns
| Type | Description |
|---|---|
[Storage](../base/storage.md?sid=django_core_files_storage_base_storage) | A new instance of the storage class specified in the BACKEND parameter, initialized with the provided OPTIONS. |