简体   繁体   English

Django 存储对 s3 static 文件使用不正确的 url

[英]Django storages using incorrect urls for s3 static files

I am using Django storages to host my static files (css, js, images) on s3.我正在使用 Django 存储在 s3 上托管我的 static 文件(css、js、图像)。 When I load my webpage django keeps pointing to the incorrect url of my s3 public bucket.当我加载我的网页时,django 一直指向我的 s3 公共存储桶的错误 url。 For example, it keeps returning https://mysite.amazonaws.com/assets/images/cat.png despite the correct public url for the file being https://mysite.s3-ap-southeast-2.amazonaws.com/assets/images/cat.png For example, it keeps returning https://mysite.amazonaws.com/assets/images/cat.png despite the correct public url for the file being https://mysite.s3-ap-southeast-2.amazonaws.com/assets/images/cat.png

settings.py设置.py

DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
AWS_ACCESS_KEY_ID = os.environ.get('aws_access_key_id')
AWS_SECRET_ACCESS_KEY = os.environ.get('aws_secret_key')
AWS_STORAGE_BUCKET_NAME = 'mysite'
AWS_DEFAULT_ACL = "private"
AWS_S3_SIGNATURE_VERSION = "s3v4"
AWS_S3_REGION_NAME = 'ap-southeast-2'
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'static'),
]
STATIC_URL = 'https://mysite.s3-ap-southeast-2.amazonaws.com/static/'
STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'

Try setting a s3 custom domain.尝试设置一个 s3 自定义域。

AWS_S3_CUSTOM_DOMAIN = 'mysite.s3-ap-southeast-2.amazonaws.com'

暂无
暂无

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

相关问题 django-storages在S3中为资产生成不正确的URL - django-storages generates incorrect urls to assets in S3 如何使用 django-storages 生成预先签名的 S3 url? - How to generate presigned S3 urls using django-storages? 使用boto3和存储将django app的静态文件上传到s3 - uploading static files of django app to s3 with boto3 and storages collectstatic 命令在部署到弹性 beantalk 时失败 | 使用 django-storages 在 S3 上存储静态文件 - collectstatic command fails while deploying to elastic beanstalk | using django-storages for storing static files on S3 用django-storages更改s3存储 - changing s3 storages with django-storages 如何使用 django-storages 和 Amazon S3 设置 Django 项目,但使用不同的文件夹来存放静态文件和媒体文件? - How to set-up a Django project with django-storages and Amazon S3, but with different folders for static files and media files? 为什么 S3(与 boto 和 django-storages 一起使用)甚至为公共文件提供签名 url? - Why does S3 (using with boto and django-storages) give signed url even for public files? 在Elastic Beanstalk上使用boto3和django-storages将Filer的文件上传到S3时出现500错误 - 500 error when uploading files with Filer to S3 using boto3 and django-storages on Elastic Beanstalk 将大文件 Django 存储上传到 AWS S3 - Upload Large files Django Storages to AWS S3 带有django-queued-storages + boto + amazon s3的私人文件 - private files with django-queued-storages + boto + amazon s3
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM