Hi everyone, I’m currently deploying my django app and want to store my static and medias files on S3.
I have the following configuration in settings.py, which works perfectly locally :
Using static folder to store my images, css, js… and media folder to store the images the user uploads.
So for example to access an image I do <img src="{% static 'my_image.png' %}">
But now that I want to use S3, I’ve created both folders in my bucket and the image is not served. Looking in details, I see that the url is :
I’m curious - how are you getting the my_bucket_name.s3.amazonaws.com as part of the url? What you’re showing here should render as /static/my_image.png.
Sorry I’m not sure to understand your question correctly.
I’ve uploaded my local static and media folders to my aws bucket. I configured it to be publicly accessible and then I made the configuration in settings.py :
The STATIC_URL setting primarily applies to the StaticFilesStorage package. I don’t see anything documented that shows that it is used with any other storage engine unless that engine specifies that it is being used.
That appears to me to be the case. I don’t see any reference to it in the django-storages docs for S3 and I don’t see it being used in the code.
Not “replaced by”. These two settings serve two different and complimentary functions for the StaticFilesStorages module.
The STATIC_ROOT setting identifies a physical path where static files are to be stored. The STATIC_URL setting identifies a logical path prefix to be applied to URLs being constructed to reference those files.
Neither of those settings appear to be relevant to the S3Storage module - at least not as far as I can see at Amazon S3 — django-storages 1.14.2 documentation. That module appears to have its own settings that it uses for those purposes.
In the same folder (where there’s settings.py), I created custom_storage.py :
from django.conf import settings
from storages.backends.s3boto3 import S3Boto3Storage
class StaticStorage(S3Boto3Storage):
location = settings.STATICFILES_LOCATION
querystring_auth = False
class MediaStorage(S3Boto3Storage):
location = settings.MEDIAFILES_LOCATION
file_overwrite = False
Then I ran python manage.py collectstatic and it created in the bucket the static folder, containing admin folder.
And manually I created my folders in the bucket.