You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
Collectstatic puts the files in the right place on s3.
Some static files are correctly served with the correct url e.g. https://cdn.mycdn.com/static/1-0/debug_toolbar/css/print.css
What doesn't work:
Some libraries like the django admin and restframework don't form the static urls correctly and are trying to access the static files at the root of the CDN, not using the /static/1-0/ path: 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.
The text was updated successfully, but these errors were encountered:
KaivG
changed the title
Static URLs are missing location part for some libraries.
Some Static URLs are malformed (missing location part) for some libraries.
Apr 28, 2024
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?
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.
The text was updated successfully, but these errors were encountered: