Python 如何告诉Django collectstatic使用AmazonS3?
我已经完成了django+S3的设置。具体而言:Python 如何告诉Django collectstatic使用AmazonS3?,python,django,collectstatic,Python,Django,Collectstatic,我已经完成了django+S3的设置。具体而言: import os # AWS credentials AWS_STORAGE_BUCKET_NAME = os.environ['AWS_STORAGE_BUCKET_NAME'] AWS_S3_CUSTOM_DOMAIN = '%s.s3.amazonaws.com' % AWS_STORAGE_BUCKET_NAME # boto config AWS_ACCESS_KEY_ID = os.environ['AWS_ACCESS_KEY_
import os
# AWS credentials
AWS_STORAGE_BUCKET_NAME = os.environ['AWS_STORAGE_BUCKET_NAME']
AWS_S3_CUSTOM_DOMAIN = '%s.s3.amazonaws.com' % AWS_STORAGE_BUCKET_NAME
# boto config
AWS_ACCESS_KEY_ID = os.environ['AWS_ACCESS_KEY_ID']
AWS_SECRET_ACCESS_KEY = os.environ['AWS_SECRET_ACCESS_KEY']
AWS_HEADERS = { # see http://developer.yahoo.com/performance/rules.html#expires
'Expires': 'Thu, 31 Dec 2099 20:00:00 GMT',
'Cache-Control': 'max-age=94608000',
}
# For the static files
STATICFILES_LOCATION = 'static'
STATICFILES_STORAGE = 'myapp.custom_storages.StaticStorage'
STATIC_URL = 'https://%s/%s/' % (AWS_S3_CUSTOM_DOMAIN, STATICFILES_LOCATION)
# For the media files
MEDIAFILES_LOCATION = 'media'
DEFAULT_FILE_STORAGE = 'myapp.custom_storages.MediaStorage'
MEDIA_URL = 'https://%s/%s/' % (AWS_S3_CUSTOM_DOMAIN, MEDIAFILES_LOCATION)
我的自定义存储是简单的S3BotoStorage
s:
from django.conf import settings
from storages.backends.s3boto import S3BotoStorage
class StaticStorage(S3BotoStorage):
location = settings.STATICFILES_LOCATION
class MediaStorage(S3BotoStorage):
location = settings.MEDIAFILES_LOCATION
我希望collectstatic
将遵守此配置(如howto中所述),并使用myapp.custom\u storages.StaticStorage
将收集的静态文件上载到S3。相反,它只使用本地文件系统。因为我:
STATIC_ROOT = os.path.join(BASE_DIR, 'mycollectstatic')
(只是因为有了“static”
对我来说太混乱了),我可以清楚地看到:
» python manage.py collectstatic
You have requested to collect static files at the destination
location as specified in your settings:
/absolute-path/mycollectstatic
This will overwrite existing files!
Are you sure you want to do this?
Type 'yes' to continue, or 'no' to cancel:
因此,似乎collectstatic
命令正在使用STATIC\u ROOT
,即使STATICFILES\u STORAGE='myapp.custom\u storages.StaticStorage'
。这是预期的吗
在使用另一个
STATICFILES\u存储时,是否应以不同方式配置STATIC\u ROOT
?这是在哪里记录的?你的python版本是什么?你使用哪些软件包?@LouisBarranqueiro:Python2.7.6,Django==1.8.5
,没有专门的软件包。你试过默认文件存储='myapp.custom\u storages.StaticStorage'
?关于,STATIC\u ROOT
属性,您不必编辑tit。这对我来说很好用。