From 3d565b7d88b206d4d786d15c88de492b0be18e31 Mon Sep 17 00:00:00 2001 From: Manan Bhavsar Date: Tue, 11 Jul 2023 14:27:08 -0400 Subject: [PATCH 1/9] changed settings.py vars to reflect django-4.2 --- .../config/settings/production.py | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/{{cookiecutter.project_slug}}/config/settings/production.py b/{{cookiecutter.project_slug}}/config/settings/production.py index 87340b88a..8ba9b5949 100644 --- a/{{cookiecutter.project_slug}}/config/settings/production.py +++ b/{{cookiecutter.project_slug}}/config/settings/production.py @@ -62,6 +62,8 @@ SECURE_HSTS_PRELOAD = env.bool("DJANGO_SECURE_HSTS_PRELOAD", default=True) # https://docs.djangoproject.com/en/dev/ref/middleware/#x-content-type-options-nosniff SECURE_CONTENT_TYPE_NOSNIFF = env.bool("DJANGO_SECURE_CONTENT_TYPE_NOSNIFF", default=True) +STORAGES = dict() + {% if cookiecutter.cloud_provider != 'None' -%} # STORAGES # ------------------------------------------------------------------------------ @@ -107,30 +109,44 @@ AZURE_CONTAINER = env("DJANGO_AZURE_CONTAINER_NAME") # ------------------------ {% endif -%} {% if cookiecutter.use_whitenoise == 'y' -%} -STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage" +STORAGES["staticfiles"] = { + "BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage", + } {% elif cookiecutter.cloud_provider == 'AWS' -%} -STATICFILES_STORAGE = "{{cookiecutter.project_slug}}.utils.storages.StaticRootS3Boto3Storage" +STORAGES["staticfiles"] = { + "BACKEND": "{{cookiecutter.project_slug}}.utils.storages.StaticRootS3Boto3Storage", + } COLLECTFAST_STRATEGY = "collectfast.strategies.boto3.Boto3Strategy" STATIC_URL = f"https://{aws_s3_domain}/static/" {% elif cookiecutter.cloud_provider == 'GCP' -%} -STATICFILES_STORAGE = "{{cookiecutter.project_slug}}.utils.storages.StaticRootGoogleCloudStorage" +STORAGES["staticfiles"] = { + "BACKEND": "{{cookiecutter.project_slug}}.utils.storages.StaticRootGoogleCloudStorage", + } COLLECTFAST_STRATEGY = "collectfast.strategies.gcloud.GoogleCloudStrategy" STATIC_URL = f"https://storage.googleapis.com/{GS_BUCKET_NAME}/static/" {% elif cookiecutter.cloud_provider == 'Azure' -%} -STATICFILES_STORAGE = "{{cookiecutter.project_slug}}.utils.storages.StaticRootAzureStorage" +STORAGES["staticfiles"] = { + "BACKEND": "{{cookiecutter.project_slug}}.utils.storages.StaticRootAzureStorage", + } STATIC_URL = f"https://{AZURE_ACCOUNT_NAME}.blob.core.windows.net/static/" {% endif -%} # MEDIA # ------------------------------------------------------------------------------ {%- if cookiecutter.cloud_provider == 'AWS' %} -DEFAULT_FILE_STORAGE = "{{cookiecutter.project_slug}}.utils.storages.MediaRootS3Boto3Storage" +STORAGES["default"] = { + "BACKEND": "{{cookiecutter.project_slug}}.utils.storages.MediaRootS3Boto3Storage", + } MEDIA_URL = f"https://{aws_s3_domain}/media/" {%- elif cookiecutter.cloud_provider == 'GCP' %} -DEFAULT_FILE_STORAGE = "{{cookiecutter.project_slug}}.utils.storages.MediaRootGoogleCloudStorage" +STORAGES["default"] = { + "BACKEND": "{{cookiecutter.project_slug}}.utils.storages.MediaRootGoogleCloudStorage", + } MEDIA_URL = f"https://storage.googleapis.com/{GS_BUCKET_NAME}/media/" {%- elif cookiecutter.cloud_provider == 'Azure' %} -DEFAULT_FILE_STORAGE = "{{cookiecutter.project_slug}}.utils.storages.MediaRootAzureStorage" +STORAGES["default"] = { + "BACKEND": "{{cookiecutter.project_slug}}.utils.storages.MediaRootAzureStorage", + } MEDIA_URL = f"https://{AZURE_ACCOUNT_NAME}.blob.core.windows.net/media/" {%- endif %} @@ -230,7 +246,7 @@ COMPRESS_ENABLED = env.bool("COMPRESS_ENABLED", default=True) COMPRESS_STORAGE = "compressor.storage.GzipCompressorFileStorage" {%- elif cookiecutter.cloud_provider in ('AWS', 'GCP', 'Azure') and cookiecutter.use_whitenoise == 'n' %} # https://django-compressor.readthedocs.io/en/latest/settings/#django.conf.settings.COMPRESS_STORAGE -COMPRESS_STORAGE = STATICFILES_STORAGE +COMPRESS_STORAGE = STORAGES["staticfiles"]["BACKEND"] {%- endif %} # https://django-compressor.readthedocs.io/en/latest/settings/#django.conf.settings.COMPRESS_URL COMPRESS_URL = STATIC_URL{% if cookiecutter.use_whitenoise == 'y' or cookiecutter.cloud_provider == 'None' %} # noqa: F405{% endif %} From 51958ec8a693a6b8bfd57f045d995ec51d24be90 Mon Sep 17 00:00:00 2001 From: Bruno Alla Date: Wed, 12 Jul 2023 10:56:57 +0100 Subject: [PATCH 2/9] Fix code style --- .../config/settings/base.py | 2 +- .../config/settings/production.py | 28 +++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/{{cookiecutter.project_slug}}/config/settings/base.py b/{{cookiecutter.project_slug}}/config/settings/base.py index c9feedea1..f02d476c1 100644 --- a/{{cookiecutter.project_slug}}/config/settings/base.py +++ b/{{cookiecutter.project_slug}}/config/settings/base.py @@ -252,7 +252,7 @@ ADMINS = [("""{{cookiecutter.author_name}}""", "{{cookiecutter.email}}")] MANAGERS = ADMINS # https://cookiecutter-django.readthedocs.io/en/latest/settings.html#other-environment-settings # Force the `admin` sign in process to go through the `django-allauth` workflow -DJANGO_ADMIN_FORCE_ALLAUTH = env.bool('DJANGO_ADMIN_FORCE_ALLAUTH', default=False) +DJANGO_ADMIN_FORCE_ALLAUTH = env.bool("DJANGO_ADMIN_FORCE_ALLAUTH", default=False) # LOGGING # ------------------------------------------------------------------------------ diff --git a/{{cookiecutter.project_slug}}/config/settings/production.py b/{{cookiecutter.project_slug}}/config/settings/production.py index 8ba9b5949..3a9cb10c5 100644 --- a/{{cookiecutter.project_slug}}/config/settings/production.py +++ b/{{cookiecutter.project_slug}}/config/settings/production.py @@ -110,24 +110,24 @@ AZURE_CONTAINER = env("DJANGO_AZURE_CONTAINER_NAME") {% endif -%} {% if cookiecutter.use_whitenoise == 'y' -%} STORAGES["staticfiles"] = { - "BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage", - } + "BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage", +} {% elif cookiecutter.cloud_provider == 'AWS' -%} STORAGES["staticfiles"] = { - "BACKEND": "{{cookiecutter.project_slug}}.utils.storages.StaticRootS3Boto3Storage", - } + "BACKEND": "{{cookiecutter.project_slug}}.utils.storages.StaticRootS3Boto3Storage", +} COLLECTFAST_STRATEGY = "collectfast.strategies.boto3.Boto3Strategy" STATIC_URL = f"https://{aws_s3_domain}/static/" {% elif cookiecutter.cloud_provider == 'GCP' -%} STORAGES["staticfiles"] = { - "BACKEND": "{{cookiecutter.project_slug}}.utils.storages.StaticRootGoogleCloudStorage", - } + "BACKEND": "{{cookiecutter.project_slug}}.utils.storages.StaticRootGoogleCloudStorage", +} COLLECTFAST_STRATEGY = "collectfast.strategies.gcloud.GoogleCloudStrategy" STATIC_URL = f"https://storage.googleapis.com/{GS_BUCKET_NAME}/static/" {% elif cookiecutter.cloud_provider == 'Azure' -%} STORAGES["staticfiles"] = { - "BACKEND": "{{cookiecutter.project_slug}}.utils.storages.StaticRootAzureStorage", - } + "BACKEND": "{{cookiecutter.project_slug}}.utils.storages.StaticRootAzureStorage", +} STATIC_URL = f"https://{AZURE_ACCOUNT_NAME}.blob.core.windows.net/static/" {% endif -%} @@ -135,18 +135,18 @@ STATIC_URL = f"https://{AZURE_ACCOUNT_NAME}.blob.core.windows.net/static/" # ------------------------------------------------------------------------------ {%- if cookiecutter.cloud_provider == 'AWS' %} STORAGES["default"] = { - "BACKEND": "{{cookiecutter.project_slug}}.utils.storages.MediaRootS3Boto3Storage", - } + "BACKEND": "{{cookiecutter.project_slug}}.utils.storages.MediaRootS3Boto3Storage", +} MEDIA_URL = f"https://{aws_s3_domain}/media/" {%- elif cookiecutter.cloud_provider == 'GCP' %} STORAGES["default"] = { - "BACKEND": "{{cookiecutter.project_slug}}.utils.storages.MediaRootGoogleCloudStorage", - } + "BACKEND": "{{cookiecutter.project_slug}}.utils.storages.MediaRootGoogleCloudStorage", +} MEDIA_URL = f"https://storage.googleapis.com/{GS_BUCKET_NAME}/media/" {%- elif cookiecutter.cloud_provider == 'Azure' %} STORAGES["default"] = { - "BACKEND": "{{cookiecutter.project_slug}}.utils.storages.MediaRootAzureStorage", - } + "BACKEND": "{{cookiecutter.project_slug}}.utils.storages.MediaRootAzureStorage", +} MEDIA_URL = f"https://{AZURE_ACCOUNT_NAME}.blob.core.windows.net/media/" {%- endif %} From 9887d24949120d142a50320439c31e992f92cb49 Mon Sep 17 00:00:00 2001 From: Manan Bhavsar Date: Thu, 13 Jul 2023 10:50:39 -0400 Subject: [PATCH 3/9] removed overriding and if block in variable --- .../config/settings/production.py | 68 +++++++++---------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/{{cookiecutter.project_slug}}/config/settings/production.py b/{{cookiecutter.project_slug}}/config/settings/production.py index 3a9cb10c5..498d30b12 100644 --- a/{{cookiecutter.project_slug}}/config/settings/production.py +++ b/{{cookiecutter.project_slug}}/config/settings/production.py @@ -62,8 +62,6 @@ SECURE_HSTS_PRELOAD = env.bool("DJANGO_SECURE_HSTS_PRELOAD", default=True) # https://docs.djangoproject.com/en/dev/ref/middleware/#x-content-type-options-nosniff SECURE_CONTENT_TYPE_NOSNIFF = env.bool("DJANGO_SECURE_CONTENT_TYPE_NOSNIFF", default=True) -STORAGES = dict() - {% if cookiecutter.cloud_provider != 'None' -%} # STORAGES # ------------------------------------------------------------------------------ @@ -105,49 +103,51 @@ AZURE_CONTAINER = env("DJANGO_AZURE_CONTAINER_NAME") {% endif -%} {% if cookiecutter.cloud_provider != 'None' or cookiecutter.use_whitenoise == 'y' -%} -# STATIC +# STATIC & MEDIA # ------------------------ -{% endif -%} -{% if cookiecutter.use_whitenoise == 'y' -%} -STORAGES["staticfiles"] = { - "BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage", +STORAGES = { +{%- if cookiecutter.use_whitenoise == 'y' -%} + "staticfiles": { + "BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage", + } +{%- elif cookiecutter.cloud_provider == 'AWS' -%} + "default": { + "BACKEND": "{{cookiecutter.project_slug}}.utils.storages.MediaRootS3Boto3Storage", + }, + "staticfiles": { + "BACKEND": "{{cookiecutter.project_slug}}.utils.storages.StaticRootS3Boto3Storage", + } +{%- elif cookiecutter.cloud_provider == 'GCP' -%} + "default": { + "BACKEND": "{{cookiecutter.project_slug}}.utils.storages.MediaRootGoogleCloudStorage", + }, + "staticfiles": { + "BACKEND": "{{cookiecutter.project_slug}}.utils.storages.StaticRootGoogleCloudStorage", + } +{%- elif cookiecutter.cloud_provider == 'Azure' -%} + "default": { + "BACKEND": "{{cookiecutter.project_slug}}.utils.storages.MediaRootAzureStorage", + }, + "staticfiles": { + "BACKEND": "{{cookiecutter.project_slug}}.utils.storages.StaticRootAzureStorage", + } +{%- endif -%} } -{% elif cookiecutter.cloud_provider == 'AWS' -%} -STORAGES["staticfiles"] = { - "BACKEND": "{{cookiecutter.project_slug}}.utils.storages.StaticRootS3Boto3Storage", -} -COLLECTFAST_STRATEGY = "collectfast.strategies.boto3.Boto3Strategy" -STATIC_URL = f"https://{aws_s3_domain}/static/" -{% elif cookiecutter.cloud_provider == 'GCP' -%} -STORAGES["staticfiles"] = { - "BACKEND": "{{cookiecutter.project_slug}}.utils.storages.StaticRootGoogleCloudStorage", -} -COLLECTFAST_STRATEGY = "collectfast.strategies.gcloud.GoogleCloudStrategy" -STATIC_URL = f"https://storage.googleapis.com/{GS_BUCKET_NAME}/static/" -{% elif cookiecutter.cloud_provider == 'Azure' -%} -STORAGES["staticfiles"] = { - "BACKEND": "{{cookiecutter.project_slug}}.utils.storages.StaticRootAzureStorage", -} -STATIC_URL = f"https://{AZURE_ACCOUNT_NAME}.blob.core.windows.net/static/" {% endif -%} -# MEDIA +# MEDIA_URL, STATIC_URL & COLLECTFAST_STRATEGY # ------------------------------------------------------------------------------ {%- if cookiecutter.cloud_provider == 'AWS' %} -STORAGES["default"] = { - "BACKEND": "{{cookiecutter.project_slug}}.utils.storages.MediaRootS3Boto3Storage", -} MEDIA_URL = f"https://{aws_s3_domain}/media/" +COLLECTFAST_STRATEGY = "collectfast.strategies.boto3.Boto3Strategy" +STATIC_URL = f"https://{aws_s3_domain}/static/" {%- elif cookiecutter.cloud_provider == 'GCP' %} -STORAGES["default"] = { - "BACKEND": "{{cookiecutter.project_slug}}.utils.storages.MediaRootGoogleCloudStorage", -} MEDIA_URL = f"https://storage.googleapis.com/{GS_BUCKET_NAME}/media/" +COLLECTFAST_STRATEGY = "collectfast.strategies.gcloud.GoogleCloudStrategy" +STATIC_URL = f"https://storage.googleapis.com/{GS_BUCKET_NAME}/static/" {%- elif cookiecutter.cloud_provider == 'Azure' %} -STORAGES["default"] = { - "BACKEND": "{{cookiecutter.project_slug}}.utils.storages.MediaRootAzureStorage", -} MEDIA_URL = f"https://{AZURE_ACCOUNT_NAME}.blob.core.windows.net/media/" +STATIC_URL = f"https://{AZURE_ACCOUNT_NAME}.blob.core.windows.net/static/" {%- endif %} # EMAIL From 8be900260bcebf8733fa40e5055b5645eee1b7c2 Mon Sep 17 00:00:00 2001 From: Bruno Alla Date: Fri, 14 Jul 2023 20:11:54 +0100 Subject: [PATCH 4/9] Fix code style --- .../config/settings/production.py | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/{{cookiecutter.project_slug}}/config/settings/production.py b/{{cookiecutter.project_slug}}/config/settings/production.py index 498d30b12..250379c7c 100644 --- a/{{cookiecutter.project_slug}}/config/settings/production.py +++ b/{{cookiecutter.project_slug}}/config/settings/production.py @@ -106,34 +106,34 @@ AZURE_CONTAINER = env("DJANGO_AZURE_CONTAINER_NAME") # STATIC & MEDIA # ------------------------ STORAGES = { -{%- if cookiecutter.use_whitenoise == 'y' -%} +{%- if cookiecutter.use_whitenoise == 'y' %} "staticfiles": { "BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage", - } -{%- elif cookiecutter.cloud_provider == 'AWS' -%} + }, +{%- elif cookiecutter.cloud_provider == 'AWS' %} "default": { "BACKEND": "{{cookiecutter.project_slug}}.utils.storages.MediaRootS3Boto3Storage", }, "staticfiles": { "BACKEND": "{{cookiecutter.project_slug}}.utils.storages.StaticRootS3Boto3Storage", - } -{%- elif cookiecutter.cloud_provider == 'GCP' -%} + }, +{%- elif cookiecutter.cloud_provider == 'GCP' %} "default": { "BACKEND": "{{cookiecutter.project_slug}}.utils.storages.MediaRootGoogleCloudStorage", }, "staticfiles": { "BACKEND": "{{cookiecutter.project_slug}}.utils.storages.StaticRootGoogleCloudStorage", - } -{%- elif cookiecutter.cloud_provider == 'Azure' -%} + }, +{%- elif cookiecutter.cloud_provider == 'Azure' %} "default": { "BACKEND": "{{cookiecutter.project_slug}}.utils.storages.MediaRootAzureStorage", }, "staticfiles": { "BACKEND": "{{cookiecutter.project_slug}}.utils.storages.StaticRootAzureStorage", - } -{%- endif -%} + }, +{%- endif %} } -{% endif -%} +{%- endif %} # MEDIA_URL, STATIC_URL & COLLECTFAST_STRATEGY # ------------------------------------------------------------------------------ From ee655c3013d7163b23333480f9d50647a9204a0d Mon Sep 17 00:00:00 2001 From: Bruno Alla Date: Fri, 14 Jul 2023 20:12:45 +0100 Subject: [PATCH 5/9] Remove comment --- {{cookiecutter.project_slug}}/config/settings/production.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/{{cookiecutter.project_slug}}/config/settings/production.py b/{{cookiecutter.project_slug}}/config/settings/production.py index 250379c7c..110cf8486 100644 --- a/{{cookiecutter.project_slug}}/config/settings/production.py +++ b/{{cookiecutter.project_slug}}/config/settings/production.py @@ -135,8 +135,6 @@ STORAGES = { } {%- endif %} -# MEDIA_URL, STATIC_URL & COLLECTFAST_STRATEGY -# ------------------------------------------------------------------------------ {%- if cookiecutter.cloud_provider == 'AWS' %} MEDIA_URL = f"https://{aws_s3_domain}/media/" COLLECTFAST_STRATEGY = "collectfast.strategies.boto3.Boto3Strategy" From 4a1917b76a9b5f29129954ad0a4ed146083e7f64 Mon Sep 17 00:00:00 2001 From: Manan Bhavsar Date: Thu, 13 Jul 2023 10:50:39 -0400 Subject: [PATCH 6/9] removed overriding and if block in variable --- .../config/settings/production.py | 68 +++++++++---------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/{{cookiecutter.project_slug}}/config/settings/production.py b/{{cookiecutter.project_slug}}/config/settings/production.py index 3a9cb10c5..498d30b12 100644 --- a/{{cookiecutter.project_slug}}/config/settings/production.py +++ b/{{cookiecutter.project_slug}}/config/settings/production.py @@ -62,8 +62,6 @@ SECURE_HSTS_PRELOAD = env.bool("DJANGO_SECURE_HSTS_PRELOAD", default=True) # https://docs.djangoproject.com/en/dev/ref/middleware/#x-content-type-options-nosniff SECURE_CONTENT_TYPE_NOSNIFF = env.bool("DJANGO_SECURE_CONTENT_TYPE_NOSNIFF", default=True) -STORAGES = dict() - {% if cookiecutter.cloud_provider != 'None' -%} # STORAGES # ------------------------------------------------------------------------------ @@ -105,49 +103,51 @@ AZURE_CONTAINER = env("DJANGO_AZURE_CONTAINER_NAME") {% endif -%} {% if cookiecutter.cloud_provider != 'None' or cookiecutter.use_whitenoise == 'y' -%} -# STATIC +# STATIC & MEDIA # ------------------------ -{% endif -%} -{% if cookiecutter.use_whitenoise == 'y' -%} -STORAGES["staticfiles"] = { - "BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage", +STORAGES = { +{%- if cookiecutter.use_whitenoise == 'y' -%} + "staticfiles": { + "BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage", + } +{%- elif cookiecutter.cloud_provider == 'AWS' -%} + "default": { + "BACKEND": "{{cookiecutter.project_slug}}.utils.storages.MediaRootS3Boto3Storage", + }, + "staticfiles": { + "BACKEND": "{{cookiecutter.project_slug}}.utils.storages.StaticRootS3Boto3Storage", + } +{%- elif cookiecutter.cloud_provider == 'GCP' -%} + "default": { + "BACKEND": "{{cookiecutter.project_slug}}.utils.storages.MediaRootGoogleCloudStorage", + }, + "staticfiles": { + "BACKEND": "{{cookiecutter.project_slug}}.utils.storages.StaticRootGoogleCloudStorage", + } +{%- elif cookiecutter.cloud_provider == 'Azure' -%} + "default": { + "BACKEND": "{{cookiecutter.project_slug}}.utils.storages.MediaRootAzureStorage", + }, + "staticfiles": { + "BACKEND": "{{cookiecutter.project_slug}}.utils.storages.StaticRootAzureStorage", + } +{%- endif -%} } -{% elif cookiecutter.cloud_provider == 'AWS' -%} -STORAGES["staticfiles"] = { - "BACKEND": "{{cookiecutter.project_slug}}.utils.storages.StaticRootS3Boto3Storage", -} -COLLECTFAST_STRATEGY = "collectfast.strategies.boto3.Boto3Strategy" -STATIC_URL = f"https://{aws_s3_domain}/static/" -{% elif cookiecutter.cloud_provider == 'GCP' -%} -STORAGES["staticfiles"] = { - "BACKEND": "{{cookiecutter.project_slug}}.utils.storages.StaticRootGoogleCloudStorage", -} -COLLECTFAST_STRATEGY = "collectfast.strategies.gcloud.GoogleCloudStrategy" -STATIC_URL = f"https://storage.googleapis.com/{GS_BUCKET_NAME}/static/" -{% elif cookiecutter.cloud_provider == 'Azure' -%} -STORAGES["staticfiles"] = { - "BACKEND": "{{cookiecutter.project_slug}}.utils.storages.StaticRootAzureStorage", -} -STATIC_URL = f"https://{AZURE_ACCOUNT_NAME}.blob.core.windows.net/static/" {% endif -%} -# MEDIA +# MEDIA_URL, STATIC_URL & COLLECTFAST_STRATEGY # ------------------------------------------------------------------------------ {%- if cookiecutter.cloud_provider == 'AWS' %} -STORAGES["default"] = { - "BACKEND": "{{cookiecutter.project_slug}}.utils.storages.MediaRootS3Boto3Storage", -} MEDIA_URL = f"https://{aws_s3_domain}/media/" +COLLECTFAST_STRATEGY = "collectfast.strategies.boto3.Boto3Strategy" +STATIC_URL = f"https://{aws_s3_domain}/static/" {%- elif cookiecutter.cloud_provider == 'GCP' %} -STORAGES["default"] = { - "BACKEND": "{{cookiecutter.project_slug}}.utils.storages.MediaRootGoogleCloudStorage", -} MEDIA_URL = f"https://storage.googleapis.com/{GS_BUCKET_NAME}/media/" +COLLECTFAST_STRATEGY = "collectfast.strategies.gcloud.GoogleCloudStrategy" +STATIC_URL = f"https://storage.googleapis.com/{GS_BUCKET_NAME}/static/" {%- elif cookiecutter.cloud_provider == 'Azure' %} -STORAGES["default"] = { - "BACKEND": "{{cookiecutter.project_slug}}.utils.storages.MediaRootAzureStorage", -} MEDIA_URL = f"https://{AZURE_ACCOUNT_NAME}.blob.core.windows.net/media/" +STATIC_URL = f"https://{AZURE_ACCOUNT_NAME}.blob.core.windows.net/static/" {%- endif %} # EMAIL From cf73cb62a34160c64f61f6dad73c6569ee3d871b Mon Sep 17 00:00:00 2001 From: Bruno Alla Date: Fri, 14 Jul 2023 20:11:54 +0100 Subject: [PATCH 7/9] Fix code style --- .../config/settings/production.py | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/{{cookiecutter.project_slug}}/config/settings/production.py b/{{cookiecutter.project_slug}}/config/settings/production.py index 498d30b12..250379c7c 100644 --- a/{{cookiecutter.project_slug}}/config/settings/production.py +++ b/{{cookiecutter.project_slug}}/config/settings/production.py @@ -106,34 +106,34 @@ AZURE_CONTAINER = env("DJANGO_AZURE_CONTAINER_NAME") # STATIC & MEDIA # ------------------------ STORAGES = { -{%- if cookiecutter.use_whitenoise == 'y' -%} +{%- if cookiecutter.use_whitenoise == 'y' %} "staticfiles": { "BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage", - } -{%- elif cookiecutter.cloud_provider == 'AWS' -%} + }, +{%- elif cookiecutter.cloud_provider == 'AWS' %} "default": { "BACKEND": "{{cookiecutter.project_slug}}.utils.storages.MediaRootS3Boto3Storage", }, "staticfiles": { "BACKEND": "{{cookiecutter.project_slug}}.utils.storages.StaticRootS3Boto3Storage", - } -{%- elif cookiecutter.cloud_provider == 'GCP' -%} + }, +{%- elif cookiecutter.cloud_provider == 'GCP' %} "default": { "BACKEND": "{{cookiecutter.project_slug}}.utils.storages.MediaRootGoogleCloudStorage", }, "staticfiles": { "BACKEND": "{{cookiecutter.project_slug}}.utils.storages.StaticRootGoogleCloudStorage", - } -{%- elif cookiecutter.cloud_provider == 'Azure' -%} + }, +{%- elif cookiecutter.cloud_provider == 'Azure' %} "default": { "BACKEND": "{{cookiecutter.project_slug}}.utils.storages.MediaRootAzureStorage", }, "staticfiles": { "BACKEND": "{{cookiecutter.project_slug}}.utils.storages.StaticRootAzureStorage", - } -{%- endif -%} + }, +{%- endif %} } -{% endif -%} +{%- endif %} # MEDIA_URL, STATIC_URL & COLLECTFAST_STRATEGY # ------------------------------------------------------------------------------ From c15e6d7412757bbb790e354734db669f52304bac Mon Sep 17 00:00:00 2001 From: Bruno Alla Date: Fri, 14 Jul 2023 20:12:45 +0100 Subject: [PATCH 8/9] Remove comment --- {{cookiecutter.project_slug}}/config/settings/production.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/{{cookiecutter.project_slug}}/config/settings/production.py b/{{cookiecutter.project_slug}}/config/settings/production.py index 250379c7c..110cf8486 100644 --- a/{{cookiecutter.project_slug}}/config/settings/production.py +++ b/{{cookiecutter.project_slug}}/config/settings/production.py @@ -135,8 +135,6 @@ STORAGES = { } {%- endif %} -# MEDIA_URL, STATIC_URL & COLLECTFAST_STRATEGY -# ------------------------------------------------------------------------------ {%- if cookiecutter.cloud_provider == 'AWS' %} MEDIA_URL = f"https://{aws_s3_domain}/media/" COLLECTFAST_STRATEGY = "collectfast.strategies.boto3.Boto3Strategy" From 92d27631e4a68e086841faa382a8b97fa0b4c76c Mon Sep 17 00:00:00 2001 From: Manan Bhavsar Date: Sun, 16 Jul 2023 01:12:23 -0400 Subject: [PATCH 9/9] added default storages --- {{cookiecutter.project_slug}}/config/settings/base.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/{{cookiecutter.project_slug}}/config/settings/base.py b/{{cookiecutter.project_slug}}/config/settings/base.py index f02d476c1..efc3c3194 100644 --- a/{{cookiecutter.project_slug}}/config/settings/base.py +++ b/{{cookiecutter.project_slug}}/config/settings/base.py @@ -183,6 +183,16 @@ MEDIA_ROOT = str(APPS_DIR / "media") # https://docs.djangoproject.com/en/dev/ref/settings/#media-url MEDIA_URL = "/media/" +# DEFAULT STORAGES +# ------------------------------------------------------------------------------ +STORAGES = { + "default": { + "BACKEND": "django.core.files.storage.FileSystemStorage", + }, + "staticfiles": { + "BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage", + }, +} # TEMPLATES # ------------------------------------------------------------------------------ # https://docs.djangoproject.com/en/dev/ref/settings/#templates