【发布时间】:2013-06-24 23:12:50
【问题描述】:
我打算从sorl.thumbnail.base 继承ThumbnailBackend 类。我需要做的是覆盖_get_thumbnail_filename 方法,为原始(父)方法生成的文件名添加一些内容。为此,我写了这样的东西:
from sorl.thumbnail.base import ThumbnailBackend
class MyThumbnailBackend(ThumbnailBackend):
def _get_thumbnail_filename(self, source, geometry_string, options):
oldpath = super(ThumbnailBackend,self)._get_thumbnail_filename(source, geometry_string, options)
oldpathlist = oldpath.split('/')
# get the last item of 'oldpathlist' and
# sufix it with useful info...
# join the items with the modified one...
return newpath
python继承应该缺少一些东西,因为我不断收到以下错误:
AttributeError at /location/of/the/caller/class/
'super' object has no attribute '_get_thumbnail_filename'
如果我是对的,我将在第一行导入this class:from sorl.thumbnail.base import ThumbnailBackend,其中肯定有一个_get_thumbnail_filename 方法。
我做错了什么?
非常感谢!
【问题讨论】:
标签: django inheritance sorl-thumbnail overriding