How to change or redefine sketch cache path for sorting and add image with absolute path?

I have a mediaservice site and my file vault is in a different folder from the media folder, and I want to cache thumbnails in another folder. How can I change the thumbnail cache folder and how can I give an image with an absolute path to make thumbnail?

+4
source share
1 answer

Take a look at the class responsible for naming thumbnails created using the sorl sketch.

You can subclass it and use your own class as your sketch:

# in your settings.py: THUMBNAIL_BACKEND = 'path.to.MyThumbnailBackend' #some module, in one of yours apps: from sorl.thumbnail.base import ThumbnailBackend from sorl.thumbnail.conf import settings from sorl.thumbnail.helpers import tokey, serialize class MyThumbnailBackend(ThumbnailBackend): def _get_thumbnail_filename(self, source, geometry_string, options): """ Computes the destination filename. """ key = tokey(source.key, geometry_string, serialize(options)) # make some subdirs path = '%s/%s/%s' % (key[:2], key[2:4], key) return '%s%s.%s' % (settings.THUMBNAIL_PREFIX, path, EXTENSIONS[options['format']]) 

The previous snippet was the source code of _get_thumbnail_filename . You can configure this code to generate a name at a time convenient for you.

+4
source

Source: https://habr.com/ru/post/1480939/


All Articles