Pass multiple arguments to a custom filter Django

340 Views Asked by At

I have a custom filter that looks like this

register = template.Library()

@register.filter
def makebreadcrumbs(value, arg):
    pass
    

How can I pass multiple arguments to the filter?

  {% with request.resolver_match.namespace as name_space %}
    {{ request.path|makebreadcrumbs:name_space|safe }}
  {% endwith %} 

In the code above makebreadcrumbs is my custom filter, request.path is a variable (value), and name_space is an argument.

1

There are 1 best solutions below

3
0sVoid On

I think what you want is a Django simple tag which can accept multiple arguments:

@register.simple_tag(takes_context=True)
def breadcrumbs(path, name_space):
   # your code
   return ...
{% breadcrumbs request.path request.resolver_match.namespace %}