【问题标题】:django s3 storages does not recognise the bucket namedjango s3 storages 无法识别存储桶名称
【发布时间】:2017-06-16 16:30:39
【问题描述】:

我正在使用django-s3-storage==0.11.2boto3==1.4.4。这些在settings.py中:

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}$"

我已经创建了存储桶,存储桶名称是正确的。因为这有效并且不会给出任何错误:

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

我不知道我在这里错过了什么?请你帮帮我。

【问题讨论】:

  • 在 settings.py 的 INSTALLED_APPS 部分你添加了 django_s3_storage 吗?
  • @tom 是的,我已将其添加到设置中已安装的应用程序中。

标签: django boto boto3


【解决方案1】:

好吧,我也觉得很困惑。

以下是我的观察 -

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.

您能否尝试在您的 settings.py 中更改 AWS_S3_BUCKET_NAME_STATIC = bass-line-shop

如果有帮助,请告诉我!

【讨论】:

  • 我的存储桶名称是bass-line-shop,应该类似于正则表达式模式。而且,更改 AWS_STORAGE_BUCKET_NAME 也无济于事。
  • 好的,尝试在你的 settings.py 中添加 AWS_S3_BUCKET_NAME_STATIC = bass-line-shop
  • 是的,AWS_S3_BUCKET_NAME_STATIC 提供了帮助。
  • 好的,抱歉我忘记了。
猜你喜欢
  • 2016-07-01
  • 2014-06-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-12-28
相关资源
最近更新 更多