![](/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.