1👍
✅
Here ,
It is possible and fairly simple.
Django only allows one argument to your filter, but there’s no reason you can’t put all your arguments into a single string using a comma to separate them.
So for example, if you want a filter that checks if variable X is in the list [1,2,3,4] you will want a template filter that looks like this:
{% if X|is_in:”1,2,3,4″ %}
Now we can create your templatetag like this:
from django.template import Library
register = Library()
def is_in(var, args):
if args is None:
return False
arg_list = [arg.strip() for arg in args.split(',')]
return var in arg_list
register.filter(is_in)
How do I add multiple arguments to my custom template filter in a django template?
Source:stackexchange.com