.. image:: https://badge.fury.io/py/django-fallback-storage.png
.. image:: https://travis-ci.org/simpleenergy/django-fallback-storage.png?branch=master
``django-fallback-storage`` allows for the use of multiple storage engines at
the same time. It works by iterating through the declared storage backends
until one succeeds with the desired storage action.
While usable in a production environment, this tool was primarily designed to
help with development of a project.
Consider a production site using the ``S3BotoStorage`` backend to store its
static assets on Amazon S3 and a development environment that regularly gets
database dumps from the production environment. In order to get the media
associated with the database dump to work, the development environment could be
configured to use the same S3 bucket. This could be problematic, as it would
risk making unwanted modifications to the production media.
The ``FallbackStorage`` backend provided by ``django-fallback-storage`` allows
use of the same production production media source in the development
environment while delegating all write operations to a different storage
backend (such as the filesystem).
This is accomplished by wrapping multiple storage backends, and iterating
through them for each request until one of them returns a successful response.
1. Install the package::
.. code-block:: bash
$ pip install django-fallback-storage
2. Set ``fallback_storage.storage.FallbackStorage`` as your desired storage
.. code-block:: python
DEFAULT_FILE_STORAGE = "fallback_storage.storage.FallbackStorage"
3. Declare what storage backends fallback storage should use.::
.. code-block:: python
# All operations will be tried first on `FileSystemStorage` and then on
FALLBACK_STORAGES = (
``FallbackStorage`` implements all of the following backend methods.
When one of these methods is called, each backend declared in
``FALLBACK_STORAGES`` is called. The first successful response is
Any backend which does not implement a given method will be skipped over. If
none of the backends implement a called method, then an ``AttributeError`` is
Exceptions raised by any backend are reraised if none of the backends returns a
The following methods behave somewhat specially.
Will return ``True`` if the file exists in *any* of the storage backends.
Will return the set of all directories and files in all of the storage backents.
When computing a url, FallbackStorage first checks if the file exists. If
the file exists in none of the storage backends, the last backend is used to
compute the file name.
TODO: Brief introduction on what you do with files - including link to relevant help section.