How do I use sorl-thumbnail? (django)
django, django-models, python, sorl-thumbnail, thumbnails
Solution
If you want greater flexibility you can generate the thumbnail right in the view. The following is straight from the sorl-thumbnail documentation:
from sorl.thumbnail import get_thumbnail
im = get_thumbnail(my_file, '100x100', crop='center', quality=99)
`im` then is the same thing as what you'd get back from the `thumbnail` template tag. So, you can add that variable to the template context, or just some part of it. For example if you just wanted the URL:
my_context = {
'image_url': im.url,
}
Problem
I've been looking at the sorl-thumbnail's documentation, and I still can't figure out how to: - upload images to sorl-thumbnail. - selectively show images from sorl-thumbnail. (for example, load a specific image from sorl-thumbnail from a view and show it, with customized size, etc.) Could you give some specific examples on how to use this library in a django view?