python - 通过 boto3 : ImproperlyConfigured 使用 Amazon S3 的 Django

标签 python django amazon-s3 boto boto3

我关注了this tutorial使用 Django 设置 Amazon S3。 但是当我使用 Python 3.3 时,我安装了一个 Python-3 compatible fork django-storages 和 boto3相反。

这里是 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'

当我尝试 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

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

最佳答案

所有配置都OK,就是乱码。 要使用 Django 和 Python 3+ 配置 Amazon S3,我必须使用:

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

所以,pip install django-storages-redux, boto 会非常有效 :)

关于python - 通过 boto3 : ImproperlyConfigured 使用 Amazon S3 的 Django,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31453451/

相关文章:

python - 如何将 Django 与 Jade 结合起来

django - 模拟 Django 用户的最佳方法是什么?

javascript - DJANGO 使用 ajax 在基本模板中加载/包含模板

docker - Minio:如何在启动 minio 服务器时使挂载点中已有的文件夹和文件可用?

python - 从文本文件中打印按整数排序的城市名称

python - 全屏打开cmd

amazon-web-services - 将数据从 Amazon S3 复制到 Redshift 并避免重复行

php - 使用适用于 PHP 的 AWS 开发工具包上传的 Amazon S3 文件始终为 “application/octet-stream”?

python - 获取 x 和 y 之间的 n 个数字的列表

python - 如何从 Django RawQuerySet 获取元组列表?