I have tried this a few ways. Per the docs, I have done this in my app’s ini:
[app:myapp]
#...
jinja2.filters =
islist = myapp.machines.islist
My function is simply:
def islist(item):
return isinstance(item, list)
I can tell the filter setup line in the ini file is being read, because if I get the dotted path to my islist function wrong, the app throws an error.
However, when I try to use the islist function in a template, the template can’t find the function.
{% if islist([]) %}a list{% else %}not a list{% endif %}
Results in this:
UndefinedError: 'islist' is undefined
What am I doing wrong?? Any help would be awesome.
I think filters are not exposed as functions in the namespace but rather are only invoked via the pipe. For example
{{ foo | some_filter }}.