gpt4 book ai didi

python - Django S3BotoStorage __init__ 覆盖错误, "has no attribute ' rsplit'"

转载 作者:行者123 更新时间:2023-12-01 04:18:04 25 4
gpt4 key购买 nike

跟踪的最后几行:

  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.pyprod.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'

最佳答案

looks like STATICFILES_STORAGE 需要一个表示模块路径的字符串:

STATICFILES_STORAGE='path.to.your.S3StaticStorage'

关于python - Django S3BotoStorage __init__ 覆盖错误, "has no attribute ' rsplit'",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34079060/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com