简体   繁体   English

Django-App s3 存储桶无法正常工作

[英]Django-App s3 bucket not working properly

So I'm currently deploying my website on heroku and I want to serve the static and media files from AWS S3, and at this point the files are being served from aws but the styling is not being applied.所以我目前正在 heroku 上部署我的网站,我想从 AWS S3 提供 static 和媒体文件,此时文件是从 aws 提供的,但没有应用样式。

在此处输入图像描述

This are my settings:这是我的设置:

AWS_ACCESS_KEY_ID = os.environ.get('AWS_ACCESS_KEY_ID')
AWS_SECRET_ACCESS_KEY = os.environ.get('AWS_SECRET_ACCESS_KEY')
AWS_STORAGE_BUCKET_NAME = os.environ.get('AWS_STORAGE_BUCKET_NAME')
AWS_S3_FILE_OVERWRITE = False
AWS_S3_CUSTOM_DOMAIN = f'{AWS_STORAGE_BUCKET_NAME}.s3.amazonws.com'
AWS_S3_OBJECT_PARAMETERS = {'CacheControl' : 'max-age=86400'}
AWS_DEFAULT_ACL = 'public-read'
AWS_S3_REGION_NAME = 'eu-west-3'

# AWS_S3_SIGNATURE_VERSION = 's3v4's3

AWS_LOCATION = 'static'
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'static')
]
STATICFILES_STORAGE = 'storages.backends.s3boto3.S3StaticStorage'
STATIC_URL = f'https://{AWS_S3_CUSTOM_DOMAIN}/{AWS_LOCATION}/'

DEFAULT_FILE_STORAGE = "joaoLina.storages.MediaStorage"
MEDIA_URL = f'https://{AWS_S3_CUSTOM_DOMAIN}/media/'

I have the right permissions on my bucket and as you can se the files are being served from aws:我对我的存储桶拥有正确的权限,您可以看到这些文件是从 aws 提供的: 在此处输入图像描述

So if someone knows what I'm missing I would be glad to know.因此,如果有人知道我缺少什么,我会很高兴知道。

So the problem was I did not have my cors policy set on my bucket, so after I did that everything went smooth.所以问题是我没有在我的桶上设置我的 cors 策略,所以在我这样做之后一切都很顺利。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM