追踪的最后几行:
File "/usr/local/lib64/python3.4/site-packages/django/core/files/storage.py", line 328, in get_storage_class
return import_string(import_path or settings.DEFAULT_FILE_STORAGE)
File "/usr/local/lib64/python3.4/site-packages/django/utils/module_loading.py", line 15, in import_string
module_path, class_name = dotted_path.rsplit('.', 1)
AttributeError: type object 'S3StaticStorage' has no attribute 'rsplit'
S3StaticStorage
:
class S3StaticStorage(S3BotoStorage):
def __init__(self, *args, **kwargs):
kwargs['bucket'] = getattr(settings, 'AWS_BUCKET_STATIC')
super(S3StaticStorage, self).__init__(*args, **kwargs)
我有一个名为prod.py
的文件导入common.py
,并且相应地将其配置为wsgi.py
和manage.py
中的设置来源。 prod.py
中的一行设置存储桶名称:
AWS_BUCKET_STATIC = 'myproject-static'
当我把所有东西放在一个桶里时,如果没有覆盖,这不是问题。使用此课程时是否需要导入rsplit
?看起来它应该是Python内置的,因此不需要导入。如果我理解正确,getattr(settings, 'AWS_BUCKET_STATIC')
将从Django找到的任何设置文件中获取变量,因此也不应该成为问题。
完整追踪:
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib64/python3.4/site-packages/django/core/management/__init__.py", line 350, in execute_from_command_line
utility.execute()
File "/usr/local/lib64/python3.4/site-packages/django/core/management/__init__.py", line 342, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib64/python3.4/site-packages/django/core/management/__init__.py", line 195, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/usr/local/lib64/python3.4/site-packages/django/core/management/__init__.py", line 40, in load_command_class
return module.Command()
File "/usr/local/lib64/python3.4/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 32, in __init__
self.storage.path('')
File "/usr/local/lib64/python3.4/site-packages/django/utils/functional.py", line 204, in inner
self._setup()
File "/usr/local/lib64/python3.4/site-packages/django/contrib/staticfiles/storage.py", line 394, in _setup
self._wrapped = get_storage_class(settings.STATICFILES_STORAGE)()
File "/usr/local/lib64/python3.4/site-packages/django/core/files/storage.py", line 328, in get_storage_class
return import_string(import_path or settings.DEFAULT_FILE_STORAGE)
File "/usr/local/lib64/python3.4/site-packages/django/utils/module_loading.py", line 15, in import_string
module_path, class_name = dotted_path.rsplit('.', 1)
AttributeError: type object 'S3StaticStorage' has no attribute 'rsplit'
答案 0 :(得分:2)
looks like STATICFILES_STORAGE
期待一个表示模块路径的字符串:
STATICFILES_STORAGE='path.to.your.S3StaticStorage'