2017-06-14 139 views
2

我正在使用django-s3-storage==0.11.2boto3==1.4.4。這些都是在settings.py:django s3存儲區不識別存儲桶名稱

STATIC_URL = '/static/' 
STATICFILES_DIRS = [ 
    os.path.join(BASE_DIR, "static"), 
] 
STATIC_ROOT = os.path.join(BASE_DIR, 'static_cdn') 
MEDIA_URL = '/media/' 
MEDIA_ROOT = os.path.join(BASE_DIR, 'media_cdn') 

AWS_S3_BUCKET_NAME = "my-bucket-name" 
AWS_ACCESS_KEY_ID = 'test_id_x' 
AWS_SECRET_ACCESS_KEY = 'test_id_x+test_id_x' 
DEFAULT_FILE_STORAGE = "django_s3_storage.storage.S3Storage" 
STATICFILES_STORAGE = "django_s3_storage.storage.StaticS3Storage" 
AWS_S3_ADDRESSING_STYLE = "auto" 
AWS_S3_BUCKET_AUTH_STATIC = False 
AWS_S3_MAX_AGE_SECONDS_STATIC = 60 * 60 * 24 * 365 # 1 year. 
AWS_S3_BUCKET_AUTH = False 
AWS_S3_MAX_AGE_SECONDS = 60 * 60 * 24 * 365 # 1 year. 

我也跑了這些命令:

manage.py s3_sync_meta django.core.files.storage.default_storage 

但是當我運行collectstatic或命令

manage.py s3_sync_meta django.contrib.staticfiles.storage.staticfiles_storage 

我得到這個錯誤:

botocore.exceptions.ParamValidationError: Parameter validation failed: 
Invalid bucket name "": Bucket name must match the regex "^[a-zA-Z0-9.\-_]{1,255}$" 

I已經創建了存儲桶,並且存儲桶名稱是正確的。因爲這個工程並沒有給出任何錯誤:

s3.meta.client.head_bucket(Bucket='my-bucket-name') 

我不知道我在這裏錯過了什麼?你能幫我解決嗎?

+0

在settings.py中的INSTALLED_APPS部分添加了__django_s3_storage__嗎? – tom

+0

@tom是的,我已將它添加到設置中的已安裝應用程序。 – Kakar

回答

5

好吧,它也讓我感到困惑。

以下是我的觀察 -

1。剷鬥名稱圖案

Bucket name should not have '/' in them . 
    It would be good if you can update the AWS_S3_BUCKET_NAME from 
    "my-bucket-name" to the pattern which actually resembles with your 
    bucket name. 

    Source: https://github.com/boto/botocore/issues/680 

2。在Django S3 Storage Documentation,它說

If your are updating a project that used django-storages 
    just for S3 file storage, migration is trivial. 

    Follow the installation instructions, replacing 'storages' in INSTALLED_APPS. 
    Be sure to scrutinize the rest of your settings file for changes, 
    most notably AWS_S3_BUCKET_NAME for AWS_STORAGE_BUCKET_NAME. 

能否請您嘗試改變AWS_S3_BUCKET_NAME_STATIC =低音線店在你的settings.py?

讓我知道,如果有幫助!

+0

我的存儲桶名稱是'bass-line-shop',它應該類似於正則表達式模式。而且,更改'AWS_STORAGE_BUCKET_NAME'也無濟於事。 – Kakar

+2

好的,請嘗試在settings.py中添加AWS_S3_BUCKET_NAME_STATIC =低通線店。 – tom

+0

是的,AWS_S3_BUCKET_NAME_STATIC幫助。 – Kakar