是的,可以通过基于默认后端创建自己的后端并重载_get_thumbnail_filename
方法来实现。
例如,像这样
from sorl.thumbnail.base import ThumbnailBackend, EXTENSIONS
from sorl.thumbnail.conf import settings
from sorl.thumbnail.helpers import tokey, serialize
import os.path
class KeepNameThumbnailBackend(ThumbnailBackend):
def _get_thumbnail_filename(self, source, geometry_string, options):
"""
Computes the destination filename.
"""
key = tokey(source.key, geometry_string, serialize(options))
filename, _ext = os.path.splitext(os.path.basename(source.name))
path = '%s/%s' % (key, filename)
return '%s%s.%s' % (settings.THUMBNAIL_PREFIX, path, EXTENSIONS[options['format']])
然后你必须在你的项目中激活这个新的后端settings.py
THUMBNAIL_BACKEND = 'path.to.KeepNameThumbnailBackend'
我希望它有帮助