Django Deployment Part 2 - Integration of Django with AWS S3 Bucket-Storage to serve static files.

preview_player
Показать описание

In this second video, we will be covering how to remove internal server error. Then we go through adding S3 bucket in our Django project to serve static files.

Obtain YOUR_ACCESS_TOKEN and YOUR_SECRET_TOKEN from AWS S3 Tokens settings or from digital ocean spaces configuration.
_______________________________________________________________________________________
Installations required:

pip3 install django-storages boto3
_______________________________________________________________________________________

STATIC_URL = '/static/'
STATICFILES_DIRS = [
]

MEDIA_URL = '/media/'

# buckets settings
AWS_ACCESS_KEY_ID = 'YOUR_ACCESS_TOKEN'
AWS_SECRET_ACCESS_KEY = 'YOUR_SECRET_TOKEN'
AWS_STORAGE_BUCKET_NAME = 'YOUR_SPACE_NAME'
AWS_S3_OBJECT_PARAMETERS = {
'CacheControl': 'max-age=86400',
}
AWS_LOCATION = 'static'

DEFAULT_FILE_STORAGE = 'YOUR_DJANGO_PROJECT.utils.MediaRootS3BotoStorage'
STATICFILES_STORAGE = 'YOUR_DJANGO_PROJECT.utils.StaticRootS3BotoStorage'
_______________________________________________________________________________________

StaticRootS3BotoStorage = lambda: S3Boto3Storage(location='static')
MediaRootS3BotoStorage = lambda: S3Boto3Storage(location='media')
_______________________________________________________________________________________
In last step:

Now your static files will be served from digital ocean spaces.
Рекомендации по теме
Комментарии
Автор

Hi Ishwar, i stuck at one problem now. The whole implementation is quite smooth, i can restart nginx and supervisor without errors. Then i have removed default nginx conf from sites-enabled. However, when i access the url after setup my project nginx cof, i still see the nginx default page (Welcome to nginx!). I have double confirmed the default conf file is gone @_@ but why it is still alive? i have restart nginx and supervisor for many times, i even did sudo reboot, but all didn't work. any advice?

boonyaolee
Автор

SSL validation failed ( bucket name link) how to solve?🙏

freekeys
Автор

otal 0
0 srwxrwxrwx 1 root root 0 Feb 13 17:52 gunicorn.sock one error sir

kathanpatel
Автор

No module named 'storagesweb' sir error

kathanpatel