![](/img/trans.png)
[英]Upload files dynamically into different s3 buckets with django-storages boto3
[英]uploading static files of django app to s3 with boto3 and storages
我知道这个问题已被问过很多次,但我仍然无法让它发挥作用。 我的Env配置:
在我的requrements.txt中,我有以下依赖项
我在INSTALLED_APPS中添加了storages
。 这些是我的设置参数。
AWS_ACCESS_KEY_ID='****'
AWS_SECRET_ACCESS_KEY='****'
AWS_STORAGE_BUCKET_NAME='****'
AWS_AUTO_CREATE_BUCKET = False
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
STATICFILES_STORAGE = DEFAULT_FILE_STORAGE
AWS_LOCATION = 'static/'
当我运行./manage.py collectstatic
命令时,我收到以下错误:
File "/home/me/myproj/local/lib/python2.7/site-packages/storages/backends/s3boto.py", line 23, in <module>
raise ImproperlyConfigured("Could not load Boto's S3 bindings.\n"
django.core.exceptions.ImproperlyConfigured: Could not load Boto's S3 bindings.
See https://github.com/boto/boto
有什么想法吗? 我没有正确配置什么?
当我写评论时,我终于想出了解决方案:在你的settings.py中使用:
STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
代替:
STATICFILES_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
关于boto3的更好的文档还有一个关于图书馆的公开问题: https : //github.com/jschneier/django-storages/issues/229
我在django-storages的源代码中找到了解决方案,你可以在这里找到: https : //github.com/jschneier/django-storages/blob/master/storages/backends/s3boto3.py
如果你看一下django-storages代码( https://github.com/jschneier/django-storages/blob/master/storages/backends/s3boto.py ),当django-storage不能抛出这个错误时完整的import
语句到boto
。 我的猜测是你正在使用一个非常非常老的版本的boto。 尝试将boto
升级到2.40+版本:
pip install boto==2.44
因为, DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
你必须安装boto
pip install boto
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.