如何调用在Django模板中引用参数的函数? [英] How to call function that takes an argument in a Django template?
本文介绍了如何调用在Django模板中引用参数的函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想调用这个函数并迭代其结果。
{%for my_func(10)%}
这不行。
我尝试将函数的返回值设置为变量并迭代变量,但似乎没有办法在Django模板中设置变量。
有什么正常的方法吗?
解决方案
您不能调用需要模板参数的函数。 撰写模板标签或者过滤。
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?
解决方案
You cannot call a function that requires arguments in a template. Write a template tag or filter instead.
这篇关于如何调用在Django模板中引用参数的函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文