我一直試圖讓這個設置了大約一個星期沒有成功,所以我絕望的一些幫助在這裏。我跟着這個網站上的教程:https://www.caktusgroup.com/blog/2014/11/10/Using-Amazon-S3-to-store-your-Django-sites-static-and-media-files/來設置我的Django應用程序,並試圖在EB上部署,但它在遇到collectstatic命令時仍然失敗。Django EB使用S3存儲 - collectstatic失敗
這裏是我迄今爲止..
錯誤回溯
Traceback (most recent call last):
File "/opt/python/current/app/manage.py", line 23, in <module>
execute_from_command_line(sys.argv)
File "/opt/python/run/venv/local/lib/python3.4/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/opt/python/run/venv/local/lib/python3.4/site-packages/django/core/management/__init__.py", line 359, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/opt/python/run/venv/local/lib/python3.4/site-packages/django/core/management/base.py", line 294, in run_from_argv
self.execute(*args, **cmd_options)
File "/opt/python/run/venv/local/lib/python3.4/site-packages/django/core/management/base.py", line 345, in execute
output = self.handle(*args, **options)
File "/opt/python/run/venv/local/lib/python3.4/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 193, in handle
collected = self.collect()
File "/opt/python/run/venv/local/lib/python3.4/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 124, in collect
handler(path, prefixed_path, storage)
File "/opt/python/run/venv/local/lib/python3.4/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 337, in copy_file
if not self.delete_file(path, prefixed_path, source_storage):
File "/opt/python/run/venv/local/lib/python3.4/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 255, in delete_file
if self.storage.exists(prefixed_path):
File "/opt/python/run/venv/local/lib/python3.4/site-packages/storages/backends/s3boto.py", line 454, in exists
return k.exists()
File "/opt/python/run/venv/local/lib/python3.4/site-packages/boto/s3/key.py", line 539, in exists
return bool(self.bucket.lookup(self.name, headers=headers))
File "/opt/python/run/venv/local/lib/python3.4/site-packages/boto/s3/bucket.py", line 143, in lookup
return self.get_key(key_name, headers=headers)
File "/opt/python/run/venv/local/lib/python3.4/site-packages/boto/s3/bucket.py", line 193, in get_key
key, resp = self._get_key_internal(key_name, headers, query_args_l)
File "/opt/python/run/venv/local/lib/python3.4/site-packages/boto/s3/bucket.py", line 231, in _get_key_internal
response.status, response.reason, '')
boto.exception.S3ResponseError: S3ResponseError: 400 Bad Request
settings.py
AWS_ACCESS_KEY_ID=os.environ.get('AWS_ACCESS_KEY_ID',None)
AWS_SECRET_KEY=os.environ.get('AWS_SECRET_KEY',None)
AWS_SECRET_ACCESS_KEY=os.environ.get('AWS_SECRET_KEY', None)
AWS_STORAGE_BUCKET_NAME = '<my bucket name>'
AWS_S3_HOST='s3.us-east-2.amazonaws.com'
AWS_S3_CUSTOM_DOMAIN = '%s.s3.us-east-2.amazonaws.com' % AWS_STORAGE_BUCKET_NAME
STATICFILES_LOCATION = 'static'
STATICFILES_STORAGE = 'custom_storages.StaticStorage'
STATIC_URL = "https://%s/%s/" % (AWS_S3_CUSTOM_DOMAIN, STATICFILES_LOCATION)
MEDIAFILES_LOCATION = 'media'
MEDIA_URL = "https://%s/%s/" % (AWS_S3_CUSTOM_DOMAIN, MEDIAFILES_LOCATION)
DEFAULT_FILE_STORAGE = 'custom_storages.MediaStorage'
custom_storage.py
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
我試過幾個解決方案,包括但不限於:
- Using Django's collectstatic with boto S3 throws "Error 32: Broken Pipe" after a while
任何幫助表示讚賞。謝謝!
看着教程和事實python 3,您是否安裝過並將django-storage-redux添加到您的項目中? –
繼@AlanAvalos之後,您需要在項目中使用django-storage-redux。我的問題可以幫助你http://stackoverflow.com/questions/41427837/django-wont-serve-static-files-from-amazon-s3-with-custom-domain/41433454#41433454 –
是的,我確實安裝了django-storages -redux –