File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,3 +11,6 @@ whitenoise==6.9.0
1111djangorestframework == 3.15.2
1212django-cors-headers == 4.6.0
1313django-extensions == 3.2.3
14+
15+ django-storages == 1.14.5
16+ boto3 == 1.37.11
Original file line number Diff line number Diff line change 1+ # Cloudflare R2 Configuration
2+ R2_ACCESS_KEY_ID = your_access_key_id
3+ R2_SECRET_ACCESS_KEY = your_secret_access_key
4+ R2_ACCOUNT_ID = your_account_id
5+ R2_BUCKET_NAME = your_bucket_name
Original file line number Diff line number Diff line change @@ -298,14 +298,22 @@ def create_log_dir_for_server_errors():
298298 INTERNAL_IPS = ['127.0.0.1' ]
299299
300300
301- # https://whitenoise.readthedocs.io/en/stable/django.html
301+ # Storage configuration for Cloudflare R2
302+ AWS_ACCESS_KEY_ID = os .getenv ('R2_ACCESS_KEY_ID' )
303+ AWS_SECRET_ACCESS_KEY = os .getenv ('R2_SECRET_ACCESS_KEY' )
304+ AWS_S3_ENDPOINT_URL = f"https://{ os .getenv ('R2_ACCOUNT_ID' )} .r2.cloudflarestorage.com"
305+ AWS_STORAGE_BUCKET_NAME = os .getenv ('R2_BUCKET_NAME' )
306+ AWS_S3_REGION_NAME = 'auto' # R2 doesn't need a specific region
307+ AWS_DEFAULT_ACL = 'public-read'
308+ AWS_QUERYSTRING_AUTH = False # Don't add complex authentication-related query parameters to URLs
309+
302310STORAGES = {
303- # ...
311+ # https://whitenoise.readthedocs.io/en/stable/django.html
304312 'staticfiles' : {
305313 'BACKEND' : 'whitenoise.storage.CompressedManifestStaticFilesStorage' ,
306314 },
307315 'default' : {
308- 'BACKEND' : 'django.core.files.storage.FileSystemStorage ' ,
316+ 'BACKEND' : 'storages.backends.s3boto3.S3Boto3Storage ' ,
309317 },
310318}
311319
@@ -318,5 +326,7 @@ def create_log_dir_for_server_errors():
318326STATIC_ROOT = SERVER_PATH / 'static'
319327STATIC_URL = '/static/'
320328
329+ # Media files configuration
330+ MEDIA_URL = f'https://{ os .getenv ("R2_BUCKET_NAME" )} .r2.cloudflarestorage.com/'
331+
321332MEDIA_ROOT = SERVER_PATH / 'uploads'
322- MEDIA_URL = '/uploads/'
You can’t perform that action at this time.
0 commit comments