python 2.7 - Can't collectstatic to s3 in django using boto - s3 bucket returns a NoneType -
when want collectstatic s3 give typeerror
my settings.py
import os base_dir = os.path.dirname(os.path.dirname(__file__)) secret_key = 'something' #debug = false debug = true per_page = 12 template_debug = true allowed_hosts = ['xyz.com'] # application definition installed_apps = ( 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', ....., ......., ) if debug: installed_apps = installed_apps + ('storages',) middleware_classes = ( 'django.contrib.sessions.middleware.sessionmiddleware', 'django.middleware.common.commonmiddleware', 'django.middleware.csrf.csrfviewmiddleware', 'django.contrib.auth.middleware.authenticationmiddleware', 'django.contrib.auth.middleware.sessionauthenticationmiddleware', 'django.contrib.messages.middleware.messagemiddleware', 'django.middleware.clickjacking.xframeoptionsmiddleware', ) template_context_processors = ( "django.contrib.auth.context_processors.auth", "django.core.context_processors.debug", "django.core.context_processors.i18n", "django.core.context_processors.media", "django.core.context_processors.static", "django.core.context_processors.tz", "django.contrib.messages.context_processors.messages", ) root_urlconf = 'myproject.urls' if debug: wsgi_application = 'myproject.wsgi_production.application' else: wsgi_application = 'myproject.wsgi.application' . import s3_custom # internationalization # https://docs.djangoproject.com/en/1.7/topics/i18n/ language_code = 'en-us' time_zone = 'utc' use_i18n = true use_l10n = true use_tz = true aws_storage_bucket_name = 'bucket name' aws_access_key_id = 'key' aws_secret_access_key = 'access key' aws_s3_custom_domain ='https://bucketname.s3.amazonaws.com' if debug: staticfiles_dirs = ((os.path.join(base_dir,'mystatic')),) #static_root = os.path.join(base_dir,'static') #static_url = '/static/' #media_root = (os.path.join(base_dir,'media')) #media_url = aws_s3_custom_domain+'/media/' template_dirs = (os.path.join(base_dir,'templates'),) staticfiles_location = 'static' staticfiles_storage = 'myproject.s3_custom.staticstorage' static_url = aws_s3_custom_domain+'/'+staticfiles_location+'/' mediafiles_location = 'media' media_url = aws_s3_custom_domain+'/'+mediafiles_location+'/' default_file_storage = 'myproject.s3_custom.mediastorage' #default_file_storage = 'storages.backends.s3boto.s3botostorage' #staticfiles_storage = 'storages.backends.s3boto.s3botostorage' # databases .... .......
s3_custom.py
from storages.backends.s3boto import s3botostorage import os aws_storage_bucket_name = 'bucket name' aws_access_key_id = 'key' aws_secret_access_key = 'access key' aws_s3_custom_domain ='https://bucketname.s3.amazonaws.com' class staticstorage(s3botostorage): location = 'static' class mediastorage(s3botostorage): location = 'media'
when run in terminal python manage.py collectstatic
error is
file "manage.py", line 10, in <module> execute_from_command_line(sys.argv) file "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 385, in execute_from_command_line utility.execute() file "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 377, in execute self.fetch_command(subcommand).run_from_argv(self.argv) file "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 288, in run_from_argv self.execute(*args, **options.__dict__) file "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 338, in execute output = self.handle(*args, **options) file "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 533, in handle return self.handle_noargs(**options) file "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 168, in handle_noargs collected = self.collect() file "/usr/local/lib/python2.7/dist -packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 107, in collect handler(path, prefixed_path, storage) file "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 305, in copy_file if not self.delete_file(path, prefixed_path, source_storage): file "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 218, in delete_file if self.storage.exists(prefixed_path): file "/usr/local/lib/python2.7/dist-packages/storages/backends/s3boto.py", line 414, in exists return k.exists() file "/usr/local/lib/python2.7/dist-packages/boto/s3/key.py", line 539, in exists return bool(self.bucket.lookup(self.name, headers=headers)) file "/usr/local/lib/python2.7/dist-packages/boto/s3/bucket.py", line 142, in lookup return self.get_key(key_name, headers=headers) file "/usr/local/lib/python2.7/dist-packages/boto/s3/bucket.py", line 192, in get_key key, resp = self._get_key_internal(key_name, headers, query_args_l) file "/usr/local/lib/python2.7/dist-packages/boto/s3/bucket.py", line 199, in _get_key_internal query_args=query_args) file "/usr/local/lib/python2.7/dist-packages/boto/s3/connection.py", line 652, in make_request auth_path = self.calling_format.build_auth_path(bucket, key) file "/usr/local/lib/python2.7/dist-packages/boto/s3/connection.py", line 94, in build_auth_path path = '/' + bucket typeerror: cannot concatenate 'str' , 'nonetype' objects
please me doing wrong give precious 4 hour cannot find error
Comments
Post a Comment