views:

370

answers:

2

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

{% for item in my_func(10) %} 

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

Is there any normal way to do it?

+3  A: 

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

Ignacio Vazquez-Abrams
Very sad. I'd like to have a simplier way.
cleg
+1  A: 

I'm passing to Django's template a function, which returns me some records

Why don't you pass to Django template the variable storing function's return value, instead of the function?


I've tried to set fuction's return value to a variable and iterate over variable, but there seems to be no way to set variable in Django template.

You should set variables in Django views instead of templates, and then pass them to the template.

dolma33
This function returns some records, and parameter is their count.I'd like to control this value from template.
cleg