What is the process for using a third party filter like easy-thumbnails with Jinja2 in Django? Do I need to somehow register the filters I need to use? Specifically, I want to use the thumbnail_url
filter that I used to use like:
<img src="{{ the_thing.image|thumbnail_url:'homepage_large' }}">
I tried to convert this to the Jijnja2 syntax like so:
{{ the_thing.image|thumbnail_url('homepage_large') }}
but get the following error:
django.template.base.TemplateSyntaxError: ("no filter named 'thumbnail_url'",)
You'll need to add the filter to your Jinja2 environment:
You should be aware that the template tags in easy-thumbnails are built for Django templates. However, in this very specific case, the
thumbnail_url
function just also happens to work with Jinja2 templates.A better implementation would be to write your own functions to wrap the functionality implemented in easy-thumbnails, and to use those functions as your Jinja2 filters instead.