Django easy_thumbnails accessing image URLs

烂漫一生 提交于 2019-12-05 21:02:23

The documentation points to the thumbnail_url template filter, which can return the URL of a thumnail inside a template.

You can call the template filter like a real function from your view (or anywhere else), and it should work just as fine as in a template, e.g.:

from easy_thumbnails.templatetags.thumbnail import thumbnail_url

thumbnail_url = thumbnail_url(model_with_an_image, 'small')

Behind the scenes, the filter just calls get_thumbnailer so you could also write:

thumbnailer = get_thumbnailer(model_with_an_image)
thumbnailer.generate = False  # so a not generate a thumb if sthg went wrong
thumbnail = thumbnailer.get_thumbnail(thumbnail_options)
#  do stuff with thumbnail.url
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!