How to ManifestStaticFilesStorage with django-storages, boto3 on DigitalOcean Spaces Object Storage?

Context: I am running Django==5.1.2.


I need to have cache busting for my static files on prod.

On dev, my settings are like so

STORAGES = {
    "default": {
        "BACKEND": "django.core.files.storage.FileSystemStorage",
    },
    "staticfiles": {
        "BACKEND": "django.contrib.staticfiles.storage.ManifestStaticFilesStorage",
    },
}
STATIC_URL = "static/"
STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")

This works as you would expect. When debug=False, django uses the hashed static files for the urls.

But on prod my settings are like so

# DigitalOcean Spaces Settings
# Ref: https://www.digitalocean.com/community/tutorials/how-to-set-up-object-storage-with-django
AWS_ACCESS_KEY_ID = os.getenv("DO_SOS_ACCESS_KEY_ID")
AWS_SECRET_ACCESS_KEY = os.getenv("DO_SOS_SECRET_ACCESS_KEY")
AWS_STORAGE_BUCKET_NAME = os.getenv("DO_SOS_STORAGE_BUCKET_NAME")
AWS_S3_ENDPOINT_URL = os.getenv("DO_SOS_ENDPOINT_URL")
AWS_S3_OBJECT_PARAMETERS = {
    "CacheControl": "max-age=86400",
}
AWS_DEFAULT_ACL = "public-read"

STORAGES["default"]["BACKEND"] = "storages.backends.s3boto3.S3Boto3Storage"
STORAGES["staticfiles"]["BACKEND"] = "storages.backends.s3boto3.S3Boto3Storage"
AWS_S3_SIGNATURE_VERSION = (
    "s3v4"
)

AWS_S3_CUSTOM_DOMAIN = os.getenv("DO_SOS_CUSTOM_DOMAIN")

# Static & Media URL
STATIC_URL = f"{AWS_S3_ENDPOINT_URL}/static/"
MEDIA_URL = f"{AWS_S3_ENDPOINT_URL}/media/"

As you can see, the backend is using "storages.backends.s3boto3.S3Boto3Storage" on prod instead of "django.contrib.staticfiles.storage.ManifestStaticFilesStorage". Which is kindof my problem. Whatever static content is saved to my Digital Ocean Spaces Object Storage is not hashed. How can I configure my django project to save the hashed static files to my Spaces Object Storage?

Вернуться на верх