我已按照以下步骤进行设置:
STATIC_ROOT = BASE_DIR + '/static'
YOUR_S3_BUCKET = "tlot-static"
# DEFAULT_FILE_STORAGE = "django_s3_storage.storage.S3Storage"
STATICFILES_STORAGE = "django_s3_storage.storage.StaticS3Storage"
AWS_S3_BUCKET_NAME = AWS_S3_BUCKET_NAME_STATIC = YOUR_S3_BUCKET
# These next two lines will serve the static files directly
# from the s3 bucket
AWS_S3_CUSTOM_DOMAIN = '%s.s3.amazonaws.com' % YOUR_S3_BUCKET
STATIC_URL = "https://%s/" % AWS_S3_CUSTOM_DOMAIN
但我不断得到:
<?xml version="1.0" encoding="UTF-8"?>
<Error><Code>AccessDenied</Code><Message>Access Denied</Message><RequestId>9F85922419DD93C0</RequestId><HostId>5lV1ft+jAOTvnqCvOC/fMSolHXS8foJde8XP1LxtYytlZLjejA2gvjIurYwt9Fn8Jxlgvy5IjOI=</HostId></Error>
文件已通过collectstatic成功部署,并且我已经按照存储桶上的文档设置了cors。我还需要做什么?
答案 0 :(得分:2)
您需要在Amazon的s3设置中以最快的方式授予对文件或文件夹的公共访问权限,或者在需要更严格的访问权限时设置安全策略。
也许此链接可以帮助您: https://www.codingforentrepreneurs.com/blog/s3-static-media-files-for-django/