Setup S3 bucket in Django Project: How to set-Up amazone s3 bucket storage
Hii Viewer, welcome on our blog here we will learn that how we can setup
Amazon S3 Bucket in our django project.
So there are some miner steps, you can follow this and lets complete the
process.
1. Install the the package - boto3
pip install boto3
2. add 'storages' in INSTALLED_APPS of setting.py
#add this line in setting.pyINSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'user', 'storages', #new line ]
3. Remove MEDIA_URL and MEDIA_ROOT on your setting.py file if you
have added.
4. add code in setting.py file
#add this line in setting.pyDEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'AWS_S3_ACCESS_KEY_ID = os.environ['AWS_S3_ACCESS_KEY_ID']AWS_S3_SECRET_ACCESS_KEY = os.environ['AWS_S3_SECRET_ACCESS_KEY']AWS_STORAGE_BUCKET_NAME = 'storage-bucket-nameAWS_QUERYSTRING_AUTH = False
5. Install one more requirement
pip install django-storages
Finaly you have done, now test your code.
Comments
Post a Comment