Clean Django Storage Backend Configuration
2025-09-25TIL: You are able to pass arbitrary configuration values via the OPTIONS key to Django storage backends. They are
passed as keyword arguments to the __init__ method of the storage backend.
That fact is pointed out in the Django STORAGES documentation and I apparently even used that
before in kition-dev/djangodefaults… Using these OPTIONS I was able to turn
STATICFILES_STORAGE_HASH_EXCLUSIONS = [
"css/\"images/",
]
STORAGES = {
"staticfiles": {
"BACKEND": "myproject.storage.SelectiveManifestStaticFilesStorage",
},
}
… into …
STORAGES = {
"staticfiles": {
"BACKEND": "myproject.storage.SelectiveManifestStaticFilesStorage",
"OPTIONS": {
"hash_exclusions": [
"css/\"images/",
],
}
},
}
Having got rid of that dangling configuration value loosely floating in the settings is a win for me. As a bonus, overriding the static files storage in the test settings discards the configuration options, too. Sweet.
If your custom storage backend accepts keyword arguments, put them under OPTIONS — it keeps settings cohesive and
easier to override in different environments.
© 2025 Dennis Stritzke
Code samples are public domain unless otherwise noted.