6

我按照本教程使用 Django 设置 Amazon S3。但是当我使用 Python 3.3 时,我安装了一个兼容 Python-3的 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 的。

4

3 回答 3

8

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

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

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

于 2015-07-16T13:32:17.603 回答
3

Django-storages 现在已经内置了 python3 支持。要将 django 存储与 boto3 一起使用,以下对我有用:

pip install boto3
pip install django-storages==1.5.1  --> only version 1.5 and above have boto3 support. 

使用以下 staticfiles_storage 设置

STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'

代替:

STATICFILES_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
于 2016-12-13T11:43:03.637 回答
1

我按照文件中的代码行错误storages\backends\s3boto.py发现这个错误是缺少包google_compute_engine

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

解决方案:pip install google_compute_enginecollectstatic一次。

于 2017-05-09T16:43:18.997 回答