Django - use filter in simple_tag argument

I had a simple simple tag. And it seems that I cannot use the filter as an argument.

Here is an example. mysumis a tag. myincrease- filter. foobaris a variable, and I want to pass foobar|myincreaseto mysum.

Template:

{% mysum foobar|myincrease 1 2 %}

gives an error:

TemplateSyntaxError at /

Caught VariableDoesNotExist while rendering: Failed lookup for key [foobar|myincrease] in ...

Tag:

@register.simple_tag
def mysum(a, b, c):
    return a + b + c

Filter:

@register.filter
def myincrease(num):
    return num + 1

I worked on my original problem using other approaches. But I'm still wondering if this is by design, or my mistake, or the django's mistake, or something that was missed.

I think a call compile_filterin the simple_tagdecorator implementation will do this.

+5
source share
1 answer

All Articles