2015-07-16 16 views
5

Tôi đã theo dõi this tutorial để thiết lập Amazon S3 với Django. Nhưng khi tôi đang sử dụng Python 3.3, tôi đã cài đặt Python-3 compatible fork của django-storages và boto3 thay thế.Django với Amazon S3 qua boto3: Không đúng cấu hình

Đây là tập tin 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' 

Khi tôi cố gắng, python manage.py collectstatic tôi nhận được lỗi này:

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 

Có vẻ như phụ trợ lưu trữ là boto một, không phải là một boto3.

Trả lời

6

Tất cả cấu hình là OK, nó chỉ là một sự nhầm lẫn. Để cấu hình Amazon S3 với Django và Python 3+, tôi phải sử dụng:

  • Python 3 tương thích django-kho (tên django-kho-Redux)
  • Chuẩn gói boto (boto3 không có gì để làm với Python thực sự ..)

Vì vậy, pip install django-storages-redux, boto sẽ làm việc như là một sự quyến rũ :)

+1

Như đã đề cập ở đây https://github.com/jschneier/django-storages#history Dường như django-kho-Redux hiện đang phát hành dưới django-kho, vì vậy 'pips cài đặt django-storages' 'pip install boto' làm việc cho tôi – kraenhansen

+0

Chỉ cần lưu ý ...' boto3' thực sự là [100% Python] (https://github.com/boto/boto3) và là [giờ tương thích] (https://github.com/jschneier/django-storages/issues/57) với 'django-storages'. – alxs

2

Django-kho đã xây dựng trong hỗ trợ python3 bây giờ. Để sử dụng kho django với boto3 sau đây làm việc cho tôi:

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

sử dụng các thiết lập

STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage' 

thay vì staticfiles_storage sau:

STATICFILES_STORAGE = 'storages.backends.s3boto.S3BotoStorage' 
+0

Cố gắng di chuyển từ boto đến boto3 điều này không giải quyết được tất cả các vấn đề. –

1

tôi làm theo để dòng mã lỗi trong tập tin storages\backends\s3boto.py và thấy lỗi này thiếu gói google_compute_engine

enter image description here

enter image description here

enter image description here

Giải pháp: pip install google_compute_enginecollectstatic một lần nữa.

Các vấn đề liên quan