1

我打算ThumbnailBackendsorl.thumbnail.base. 我需要做的是覆盖该_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'

如果我是对的,我将在第一行导入这个类from sorl.thumbnail.base import ThumbnailBackend它肯定有一个_get_thumbnail_filename方法。

我究竟做错了什么?

非常感谢!

4

1 回答 1

2

您必须使用当前类调用 super ,更改super(ThumbnailBackend, self)super(MyThumbnailBackend, self),像这样

class MyThumbnailBackend(ThumbnailBackend):
    def _get_thumbnail_filename(self, source, geometry_string, options):
        return super(MyThumbnailBackend, self)._get_thumbnail_filename(source, geometry_string, options)
于 2014-02-27T05:26:25.723 回答