Custom storage engines
In the previous section, we set the storage engine to ManifestFilesStorage
. This class is provided by Django, but it is also possible to write a custom storage engine. For example, you could write a storage engine that uploads your static files to a CDN, Amazon S3, or Google Cloud bucket when you run collectstatic
.
Writing a custom storage engine is beyond the scope of this book. Third-party libraries already exist that support uploading to a variety of cloud services. One such library is Django Storages, which can be found at https://django-storages.readthedocs.io/.
The following code is a short skeleton indicating which methods you should implement to create a custom file storage engine:
from django.conf import settings from django.contrib.staticfiles import storage class CustomFilesStorage(storage.StaticFilesStorage): def __init__(self): """The class must be able...