Skip to content
This repository was archived by the owner on Dec 17, 2025. It is now read-only.

Commit e001bf0

Browse files
committed
add configuration for azure storage
1 parent 78e0839 commit e001bf0

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/bin/bash
22

3+
python manage.py collectstatic --no-input
34
python manage.py migrate --noinput
45

56
waitress-serve --port=$PORT {{cookiecutter.project_slug}}.wsgi:application

{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/settings.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,4 +303,14 @@ def google_service_account_config():
303303
STATICFILES_STORAGE = "storages.backends.gcloud.GoogleCloudStorage"
304304
GS_DEFAULT_ACL = "publicRead"
305305

306+
# Configuration for Azure Storage
307+
AS_BUCKET_NAME = env.str("AS_BUCKET_NAME", "")
308+
if AS_BUCKET_NAME:
309+
AZURE_ACCOUNT_NAME = AS_BUCKET_NAME
310+
AZURE_TOKEN_CREDENTIAL = DefaultAzureCredential()
311+
AS_STATIC_CONTAINER = env.str("AS_STATIC_CONTAINER", "static")
312+
AS_MEDIA_CONTAINER = env.str("AS_MEDIA_CONTAINER", "media")
313+
DEFAULT_FILE_STORAGE = "{{cookiecutter.project_slug}}.storage_backends.AzureMediaStorage"
314+
STATICFILES_STORAGE = "{{cookiecutter.project_slug}}.storage_backends.AzureStaticStorage"
315+
306316
DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from django.conf import settings
2+
from storages.backends.azure_storage import AzureStorage
3+
4+
class AzureStaticStorage(AzureStorage):
5+
azure_container = settings.AS_STATIC_CONTAINER
6+
expiration_secs = None
7+
8+
class AzureMediaStorage(AzureStorage):
9+
azure_container = settings.AS_MEDIA_CONTAINER
10+
expiration_secs = 3600

0 commit comments

Comments
 (0)