How to call function that takes an argument in a Django template?

cleg picture cleg · Mar 18, 2010 · Viewed 99.6k times · Source

I'm passing to Django's template a function, which returns some records. I want to call this function and iterate over its result.

{% for item in my_func(10) %} 

That doesn't work. I've tried to set the function's return value to a variable and iterate over the variable, but there seems to be no way to set a variable in a Django template.

Is there any normal way to do it?

Answer

Ignacio Vazquez-Abrams picture Ignacio Vazquez-Abrams · Mar 18, 2010

You cannot call a function that requires arguments in a template. Write a template tag or filter instead.