Django未将静态文件上传到Amazon S3

时间:2019-07-14 17:43:53

标签: python django amazon-s3 boto3 django-staticfiles

我正在尝试将我的静态文件上传到Amazon S3,但它仍在将静态文件收集在本地文件夹中。关于如何使Django collectstatic上传到S3的任何想法?

以下是相关的代码位:

使用Boto和django存储。

不良行为(自从我运行以来,已复制0个静态文件):

> python manage.py collectstatic
> 0 static files copied to '/Users/michaelninh/PycharmProjects/Collab/staticfiles', 132 unmodified, 292 post-processed.

已安装的应用程序:

    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'whitenoise.runserver_nostatic',
    'django.contrib.staticfiles',
    'django.contrib.sites',

    # third party
    'allauth',
    'allauth.socialaccount',
    'allauth.account',
    'multiselectfield',
    'easy_thumbnails',
    'image_cropping',
    'storages',

    # first party
    'user.apps.UserConfig',
    'profiles.apps.ProfilesConfig'
]

与S3的连接

AWS_ACCESS_KEY_ID = 'XXX'
AWS_SECRET_ACCESS_KEY = 'YYY'
AWS_STORAGE_BUCKET_NAME = 'ZZZ'
AWS_S3_CUSTOM_DOMAIN = '%s.s3.amazonaws.com' % AWS_STORAGE_BUCKET_NAME
AWS_S3_OBJECT_PARAMETERS = {
    'CacheControl': 'max-age=86400',
}
AWS_LOCATION = 'static'


STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static'), ]
STATIC_URL = 'https://%s/%s/' % (AWS_S3_CUSTOM_DOMAIN, AWS_LOCATION)
STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'

STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')```

0 个答案:

没有答案