我正在尝试将我的静态文件放在我的Amazon S3帐户中 我的配置如下:
pip install django-storages-redux
pip install django-boto
我的settings.py
文件是:
INSTALLED_APPS = [
...
'storages',
...
]
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static"),
)
#With this configuration, the static files (projects and applications) will stayed centralized in one directory
STATIC_ROOT = os.sep.join(os.path.abspath(__file__).split(os.sep)[:-2] + ['static-content'])
#Amazon S3 Storage
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
#DEFAULT_FILE_STORAGE = 'storages.backends.s3.S3Storage'
AWS_ACCESS_KEY_ID = get_env_variable('AWS_ACCESS_KEY_ID'),
AWS_SECRET_ACCESS_KEY = get_env_variable('AWS_SECRET_ACCESS_KEY'),
STATICFILES_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
AWS_STORAGE_BUCKET_NAME = 'neurorehabilitation-project'
当我执行collectstatic
命令时,我收到此消息:
(nrb_dev)➜ neurorehabilitation_project git:(master) ✗ python manage.py collectstatic
You have requested to collect static files at the destination
location as specified in your settings.
This will overwrite existing files!
Are you sure you want to do this?
Type 'yes' to continue, or 'no' to cancel: yes
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/bgarcial/.virtualenvs/nrb_dev/lib/python3.4/site-packages/django/core/management/__init__.py", line 350, in execute_from_command_line
utility.execute()
File "/home/bgarcial/.virtualenvs/nrb_dev/lib/python3.4/site-packages/django/core/management/__init__.py", line 342, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/bgarcial/.virtualenvs/nrb_dev/lib/python3.4/site-packages/django/core/management/base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/bgarcial/.virtualenvs/nrb_dev/lib/python3.4/site-packages/django/core/management/base.py", line 399, in execute
output = self.handle(*args, **options)
File "/home/bgarcial/.virtualenvs/nrb_dev/lib/python3.4/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 176, in handle
collected = self.collect()
File "/home/bgarcial/.virtualenvs/nrb_dev/lib/python3.4/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 107, in collect
handler(path, prefixed_path, storage)
File "/home/bgarcial/.virtualenvs/nrb_dev/lib/python3.4/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 321, in copy_file
if not self.delete_file(path, prefixed_path, source_storage):
File "/home/bgarcial/.virtualenvs/nrb_dev/lib/python3.4/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 234, in delete_file
if self.storage.exists(prefixed_path):
File "/home/bgarcial/.virtualenvs/nrb_dev/lib/python3.4/site-packages/storages/backends/s3boto.py", line 431, in exists
k = self.bucket.new_key(self._encode_name(name))
File "/home/bgarcial/.virtualenvs/nrb_dev/lib/python3.4/site-packages/storages/backends/s3boto.py", line 289, in bucket
self._bucket = self._get_or_create_bucket(self.bucket_name)
File "/home/bgarcial/.virtualenvs/nrb_dev/lib/python3.4/site-packages/storages/backends/s3boto.py", line 322, in _get_or_create_bucket
return self.connection.get_bucket(name, validate=self.auto_create_bucket)
File "/home/bgarcial/.virtualenvs/nrb_dev/lib/python3.4/site-packages/storages/backends/s3boto.py", line 278, in connection
proxy_port=self.proxy_port
File "/home/bgarcial/.virtualenvs/nrb_dev/lib/python3.4/site-packages/boto/s3/connection.py", line 190, in __init__
validate_certs=validate_certs, profile_name=profile_name)
File "/home/bgarcial/.virtualenvs/nrb_dev/lib/python3.4/site-packages/boto/connection.py", line 569, in __init__
host, config, self.provider, self._required_auth_capability())
File "/home/bgarcial/.virtualenvs/nrb_dev/lib/python3.4/site-packages/boto/auth.py", line 977, in get_auth_handler
ready_handlers.append(handler(host, config, provider))
File "/home/bgarcial/.virtualenvs/nrb_dev/lib/python3.4/site-packages/boto/auth.py", line 134, in __init__
HmacKeys.__init__(self, host, config, provider)
File "/home/bgarcial/.virtualenvs/nrb_dev/lib/python3.4/site-packages/boto/auth.py", line 71, in __init__
self.update_provider(provider)
File "/home/bgarcial/.virtualenvs/nrb_dev/lib/python3.4/site-packages/boto/auth.py", line 138, in update_provider
super(HmacAuthV1Handler, self).update_provider(provider)
File "/home/bgarcial/.virtualenvs/nrb_dev/lib/python3.4/site-packages/boto/auth.py", line 75, in update_provider
self._hmac = hmac.new(self._provider.secret_key.encode('utf-8'),
AttributeError: 'tuple' object has no attribute 'encode'
(nrb_dev)➜ neurorehabilitation_project git:(master) ✗
我将静态文件发送到Amazon S3时应该考虑哪些项目或配置?
我正在使用python3.4和Django 1.9
答案 0 :(得分:1)
从以下设置中删除尾随逗号。尾随逗号表示Python将它们视为元组而不是字符串。
AWS_ACCESS_KEY_ID = get_env_variable('AWS_ACCESS_KEY_ID')
AWS_SECRET_ACCESS_KEY = get_env_variable('AWS_SECRET_ACCESS_KEY')