Skip to content

Commit fd7deda

Browse files
committed
🔧 chore: migrate to Django 5.1 STORAGES API
- Replace deprecated DEFAULT_FILE_STORAGE with STORAGES dict - Replace deprecated STATICFILES_STORAGE with STORAGES dict - Configure S3 storage backend in production settings - Set MEDIA_URL to point to S3 custom domain - Document storage configuration in CLAUDE.md
1 parent e8a289b commit fd7deda

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

CLAUDE.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,15 @@ After upgrading Wagtail to a new version, you must:
223223
3. Clear and recollect static files: `docker compose run --rm web python pythonie/manage.py collectstatic --clear --noinput`
224224
4. **Clear your browser cache** (Ctrl+Shift+R or Cmd+Shift+R) - this is critical as Wagtail admin JavaScript files are cached and stale cache can cause the admin sidebar menu to disappear with errors like `wagtailConfig is undefined`.
225225

226+
### Storage Configuration (Django 5.1+)
227+
228+
Django 5.1 removed `DEFAULT_FILE_STORAGE` and `STATICFILES_STORAGE` settings. The project now uses the `STORAGES` API:
229+
230+
- **base.py**: Defines default storage (FileSystemStorage) and staticfiles (WhiteNoise)
231+
- **production.py**: Overrides default storage to use S3 (`storages.backends.s3boto3.S3Boto3Storage`)
232+
233+
If you see 404 errors for images after upgrading Django, ensure `STORAGES` is properly configured instead of the deprecated settings.
234+
226235
### Documentation Language
227236

228237
All documentation and code comments must be written in English to ensure all contributors can collaborate effectively.

pythonie/pythonie/settings/base.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,14 @@
156156
STATIC_ROOT = join(PROJECT_ROOT, "static")
157157
STATIC_URL = "/static/"
158158

159-
STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"
159+
STORAGES = {
160+
"default": {
161+
"BACKEND": "django.core.files.storage.FileSystemStorage",
162+
},
163+
"staticfiles": {
164+
"BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage",
165+
},
166+
}
160167

161168
STATICFILES_FINDERS = (
162169
"django.contrib.staticfiles.finders.FileSystemFinder",

pythonie/pythonie/settings/production.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,26 @@
55
# Disable debug mode
66
DEBUG = False
77

8-
DEFAULT_FILE_STORAGE = "storages.backends.s3boto3.S3Boto3Storage"
8+
# AWS S3 Storage Configuration
99
AWS_ACCESS_KEY_ID = os.getenv("AWS_ACCESS_KEY_ID")
1010
AWS_SECRET_ACCESS_KEY = os.getenv("AWS_SECRET_ACCESS_KEY")
1111
AWS_STORAGE_BUCKET_NAME = os.getenv("AWS_STORAGE_BUCKET_NAME")
1212
AWS_S3_CUSTOM_DOMAIN = "s3.python.ie"
1313
AWS_HOST = "s3-eu-west-1.amazonaws.com"
1414
AWS_DEFAULT_ACL = "public-read"
1515

16+
# Use S3 for media files (Django 5.1+ STORAGES API)
17+
STORAGES = {
18+
"default": {
19+
"BACKEND": "storages.backends.s3boto3.S3Boto3Storage",
20+
},
21+
"staticfiles": {
22+
"BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage",
23+
},
24+
}
25+
26+
MEDIA_URL = f"https://{AWS_S3_CUSTOM_DOMAIN}/"
27+
1628
# Compress static files offline
1729
# http://django-compressor.readthedocs.org/en/latest/settings/#django.conf.settings.COMPRESS_OFFLINE
1830

0 commit comments

Comments
 (0)