我正在尝试基于 S3BotoStorage 创建一个新的自定义存储类,并且我不断收到以下代码的此错误:
import sys
from django.core.files.storage import Storage
from storages.backends.s3boto import S3BotoStorage
class customStorage(S3BotoStorage):
def __init__(self, *args, **kwargs):
kwargs['bucket_name'] = 'bucket_1'
print >> sys.stderr, 'Creating MyS3Storage'
super(S3BotoStorage, self).__init__(*args, **kwargs)
错误:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/functional.py", line 184, in inner
self._setup()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/files/storage.py", line 285, in _setup
self._wrapped = get_storage_class()()
File "/Users/abisson/Sites/poka/common/storages/models.py", line 10, in __init__
super(S3BotoStorage, self).__init__(*args, **kwargs)
TypeError: object.__init__() takes no parameters
我的答案基于指向 s3boto 中的多个 S3 存储桶,它应该工作不?即使是正常情况下,我们也可以这样做:
obj1 = models.FileField(storage=S3BotoStorage(bucket='bucket_1'), upload_to=custom_upload_to)
它有效。(并将参数传递给构造函数)