In Django, we can use AWS S3 for two common things:
- For user uploaded files/images
- For Django static files
Before we cover both the use cases, let’s install a third party package, we’ll be using this third party package named
django-storages in this blog.
pip install django-storages
For user uploaded files/images:
Put this code in your project’s
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage' # AWS Credentials AWS_ACCESS_KEY_ID = "PASTE IT HERE" AWS_SECRET_ACCESS_KEY = "PASTE IT HERE" AWS_STORAGE_BUCKET_NAME = "PASTE IT HERE"
For Django static files:
For storing the Django static files in S3 bucket, the procedure is same as above, you just have to add this extra config in your
STATICFILES_STORAGE = 'storages.backends.s3boto3.S3StaticStorage'
And you are good to go now, run the
Any doubts? Write it down in the comments.
For more such crispy blogs daily, follow Dev.Junction, subscribe to our newsletter and get notified.