Django与Amazon S3通过boto3:NotperlyConfigured

Dav*_* D. 6 python django amazon-s3 boto boto3

我按照本教程使用Django设置Amazon S3.但是当我使用Python 3.3时,我安装了一个兼容Python-3的django- storagesboto3的分支.

这是settings.py文件:

AWS_STORAGE_BUCKET_NAME = os.environ['LIVIN_AWS_STORAGE_BUCKET_NAME']
S3_REGION_NAME = os.environ['LIVIN_S3_REGION_NAME']
AWS_ACCESS_KEY_ID = os.environ['LIVIN_AWS_ACCESS_KEY_ID']
AWS_SECRET_ACCESS_KEY = os.environ['LIVIN_AWS_SECRET_ACCESS_KEY']

AWS_S3_CUSTOM_DOMAIN = '%s.s3.amazonaws.com' % AWS_STORAGE_BUCKET_NAME
STATIC_URL = "https://%s/" % AWS_S3_CUSTOM_DOMAIN

# Tell the staticfiles app to use S3Boto storage when writing the collected
# static files (when you run `collectstatic`).
STATICFILES_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
Run Code Online (Sandbox Code Playgroud)

当我尝试时,python manage.py collectstatic我收到此错误:

ImportError: No module named 'boto'
During handling of the above exception, another exception occurred:
...
django.core.exceptions.ImproperlyConfigured: Could not load Boto's S3 bindings.
See https://github.com/boto/boto
Run Code Online (Sandbox Code Playgroud)

似乎存储后端是boto,而不是boto3.

Dav*_* D. 7

所有配置都没问题,这只是一个混乱.要使用Django和Python 3+配置Amazon S3,我必须使用:

  • Python 3兼容的django-storages(名为django-storages-redux)
  • 标准的boto包(boto3实际上与Python无关......)

所以,pip install django-storages-redux, boto会像魅力一样工作:)