I am trying put my static files in one bucket into my Amazon S3 account My configuration is the following:
pip install django-storages-redux pip install django-boto
My settings.py
file is:
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'
When I execute collectstatic
command, I get this message:
(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) ✗
What items or configurations should I take in account for send my static files to Amazon S3?
I am working with python3.4 and Django 1.9
Remove the trailing commas from the following settings. The trailing commas mean that Python treats them as tuples rather than strings.
AWS_ACCESS_KEY_ID = get_env_variable('AWS_ACCESS_KEY_ID')
AWS_SECRET_ACCESS_KEY = get_env_variable('AWS_SECRET_ACCESS_KEY')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.