在我的Django应用程序中,我将静态和媒体文件移到了aws S3桶中。此外,我使用弹性beanstalk部署应用程序。但是,当我打开管理页面时,它不会识别静态文件。我确定,静态文件上传到s3。我使用了以下配置;
AWS_STORAGE_BUCKET_NAME = 'bucket_name'
AWS_ACCESS_KEY_ID = 'xxxxxxxxxxxxxxxx'
AWS_SECRET_ACCESS_KEY = 'xxxxxxxxxxxxxxxxxx'
AWS_S3_CUSTOM_DOMAIN = '%s3-us-west-2.amazonaws.com' % AWS_STORAGE_BUCKET_NAME
MEDIAFILES_LOCATION = 'media'
MEDIA_URL = "https://%s/%s/" % (AWS_S3_CUSTOM_DOMAIN, MEDIAFILES_LOCATION)
DEFAULT_FILE_STORAGE = 'appName.custom_storages.MediaStorage'
STATICFILES_LOCATION = 'static'
STATICFILES_STORAGE = 'appname.custom_storages.StaticStorage'
STATIC_URL = "https://%s/%s/" % (AWS_S3_CUSTOM_DOMAIN, STATICFILES_LOCATION)
// custom_storages.py
from django.conf import settings
from storages.backends.s3boto import S3BotoStorage
class MediaStorage(S3BotoStorage):
location = settings.MEDIAFILES_LOCATION
class StaticStorage(S3BotoStorage):
location = settings.STATICFILES_LOCATION