How to pass the result of a tag to a filter in Django?

Issue

How do I pass the result of a tag to a filter in Django?

e.g.

{{ {% widthratio a b c %}|add: 2 }}

Solution

You cannot, unless the tag knows how to modify the context (those usually have xxx as variable syntax available). If it doesn’t, you can write a wrapper (as a custom tag) that will.

Answered By – Cat Plus Plus

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published