Skip to content

Commit

Permalink
Default static file backend configuration error corrected
Browse files Browse the repository at this point in the history
  • Loading branch information
theriverman committed Feb 4, 2025
1 parent 5326f96 commit 578fb73
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
31 changes: 16 additions & 15 deletions DjangoExampleProject/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,22 +147,23 @@
]}

STORAGES = { # -- ADDED IN Django 5.1
# "staticfiles": { # <-- DEFAULT STATIC FILES STORAGE DISABLED
# "BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage",
# },
"staticfiles": {
"BACKEND": "django_minio_backend.models.MinioBackendStatic",
"OPTIONS": {
"MINIO_ENDPOINT": os.getenv("GH_MINIO_ENDPOINT", "play.min.io"), # NO EXTERNAL ENDPOINT FOR STATIC FILES
"MINIO_ACCESS_KEY": os.getenv("GH_MINIO_ACCESS_KEY", "Q3AM3UQ867SPQQA43P2F"),
"MINIO_SECRET_KEY": os.getenv("GH_MINIO_SECRET_KEY", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG"),
"MINIO_USE_HTTPS": bool(distutils.util.strtobool(os.getenv("GH_MINIO_USE_HTTPS", "true"))),
"MINIO_REGION": os.getenv("GH_MINIO_REGION", "us-east-1"), # OPTIONAL
"MINIO_URL_EXPIRY_HOURS": timedelta(days=1), # OPTIONAL. Default is 7 days (longest) if not defined
"MINIO_CONSISTENCY_CHECK_ON_START": True, # OPTIONAL.
"MINIO_STATIC_FILES_BUCKET": "my-static-files-bucket", # OPTIONAL. Default = auto-generated-bucket-static-files
},
"staticfiles": { # <-- DEFAULT STATIC FILES STORAGE DISABLED
"BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage",
# Add STATIC_ROOT outside STORAGES too
},
# "staticfiles": {
# "BACKEND": "django_minio_backend.models.MinioBackendStatic",
# "OPTIONS": {
# "MINIO_ENDPOINT": os.getenv("GH_MINIO_ENDPOINT", "play.min.io"), # NO EXTERNAL ENDPOINT FOR STATIC FILES
# "MINIO_ACCESS_KEY": os.getenv("GH_MINIO_ACCESS_KEY", "Q3AM3UQ867SPQQA43P2F"),
# "MINIO_SECRET_KEY": os.getenv("GH_MINIO_SECRET_KEY", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG"),
# "MINIO_USE_HTTPS": bool(distutils.util.strtobool(os.getenv("GH_MINIO_USE_HTTPS", "true"))),
# "MINIO_REGION": os.getenv("GH_MINIO_REGION", "us-east-1"), # OPTIONAL
# "MINIO_URL_EXPIRY_HOURS": timedelta(days=1), # OPTIONAL. Default is 7 days (longest) if not defined
# "MINIO_CONSISTENCY_CHECK_ON_START": True, # OPTIONAL.
# "MINIO_STATIC_FILES_BUCKET": "my-static-files-bucket", # OPTIONAL. Default = auto-generated-bucket-static-files
# },
# },
"default": {
"BACKEND": "django_minio_backend.models.MinioBackend",
"OPTIONS": {
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ For more about `STORAGES`, see [Django 4.2 release notes / Custom file storages]
from datetime import timedelta
STORAGES = { # -- ADDED in Django 5.1
# "staticfiles": { # <-- DEFAULT STATIC FILES STORAGE
# "BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage",
# Uncomment this storage to use Django's default static files storage
# and add STATIC_ROOT outside the STORAGES dict
# },
"staticfiles": {
"BACKEND": "django_minio_backend.models.MinioBackendStatic",
"OPTIONS": {
Expand Down Expand Up @@ -250,6 +255,7 @@ The following list summarises the key characteristics of **django-minio-backend*
* STATIC files are stored in a single bucket managed via `MINIO_STATIC_FILES_BUCKET`.
* STATIC files are **public** by default and must remain public to avoid certain Django admin errors.
* The value of `MEDIA_URL` is ignored, but it must be defined otherwise Django will throw an error.
* If you're serving static files with the default backend, add `STATIC_ROOT` outside `STORAGES` in your settings.
* Bucket existence is **not** checked on a save by default.
To enable this guard, set `MINIO_BUCKET_CHECK_ON_SAVE = True` in your `settings.py`.
* Bucket existences are **not** checked on Django start by default.
Expand Down
4 changes: 2 additions & 2 deletions django_minio_backend/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def ready(self):
raise ConfigurationError("STORAGES not configured in settings. Cannot use Django minio backend.")
# Verify STATIC storage backend
staticfiles = storages.backends.get("staticfiles")
if staticfiles["BACKEND"] == f"{MinioBackend.__module__}.{MinioBackendStatic.__name__}":
if staticfiles and staticfiles["BACKEND"] == f"{MinioBackend.__module__}.{MinioBackendStatic.__name__}":
# Validate configuration combinations for EXTERNAL ENDPOINT
if "OPTIONS" not in staticfiles:
raise ConfigurationError("OPTIONS not configured in STORAGES. Cannot use Django minio backend.")
Expand All @@ -44,7 +44,7 @@ def ready(self):
continue # ignore other storage backend
if "OPTIONS" not in storage_config:
raise ConfigurationError("OPTIONS not configured in STORAGES. Cannot use Django minio backend.")
options = staticfiles["OPTIONS"]
options = storage_config["OPTIONS"]
external_address = bool(options.get('MINIO_EXTERNAL_ENDPOINT'))
external_use_https = options.get('MINIO_EXTERNAL_ENDPOINT_USE_HTTPS')
if (external_address and external_use_https is None) or (not external_address and external_use_https):
Expand Down

0 comments on commit 578fb73

Please sign in to comment.