How to set up AWS S3 in Django?
AWS S3 in Django
·May 31, 2022·
1 min read
Play this article
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.
- LinkedIn: https://www.linkedin.com/in/mnamegaurav/
- YouTube: https://www.youtube.com/c/devjunction
- Website: https://gaurav.devjunction.in/
- GitHub: https://github.com/mnamegaurav
- Instagram: https://www.instagram.com/mnamegaurav/
- Twitter: https://twitter.com/mnamegaurav