Closed KaivG closed 3 months ago
The solution seems to indicate that the way BaseStorage handles settings is buggy, can you try to confirm that?
Do you have staticfiles in your INSTALLED_APPS
?
Can you share a bit more details? I strongly suspect you are hitting the comment on this bug that was fixed. In short, are you on 4.2.5+ and also do you have another package that hasn't transitioned to the new STORAGES setting?
Please reopen when there is more data, I simply cannot reproduce this or related issues.
Edit (Fix found): I found the solution to get it working. I was missing
AWS_LOCATION = STATIC_LOCATION
. Adding that line made the static path work correctly for all libraries. It seems a bit confusing however, as AWS_LOCATION to me sounds like a generic location, not just for static files. However, now the static and media paths are both working. I would rather have thought that specifying the location in STORAGES should be sufficient, or that AWS_LOCATION should be a generic path that is applied for all data stored including media files. If this is all expected behavior, it may help to clarify this in the docs.Original issue: This issue seems to be related to other ones, but I haven't seen this specific problem raised.
I have the following config to use an s3 for static and media files with cloudfront in django 4.2:
CLOUDFRONT_DOMAIN = os.environ.get("CLOUDFRONT_DOMAIN") APP_VERSION = "1-0" STATIC_LOCATION = "static/" + APP_VERSION STATIC_URL = f'https://{CLOUDFRONT_DOMAIN}/{STATIC_LOCATION}/'
PUBLIC_MEDIA_LOCATION = "media" MEDIA_URL = f"{CLOUDFRONT_DOMAIN}/{PUBLIC_MEDIA_LOCATION}/"
AWS_STORAGE_BUCKET_NAME = os.environ.get("AWS_STORAGE_BUCKET_NAME") AWS_S3_CUSTOM_DOMAIN = CLOUDFRONT_DOMAIN AWS_S3_REGION_NAME = 'af-south-1'
STORAGES = { "default": { "BACKEND": "storages.backends.s3boto3.S3Boto3Storage", "OPTIONS": { "location": "media", }, }, "staticfiles": { "BACKEND": "storages.backends.s3boto3.S3Boto3Storage", "OPTIONS": { "location": STATIC_LOCATION, }, }, }
What works:
https://cdn.mycdn.com/static/1-0/debug_toolbar/css/print.css
What doesn't work:
https://cdn.mycdn.com/admin/css/nav_sidebar.css
and are failing accordingly.I would very much appreciate a fix or work-around, as this is currently preventing me from using s3 for static files.