我想要实现的是在 Django 模板中进行计算,在简单的数学中,这将是:
section_angle = base_angle + ( sections_length / current_iteration_counter_over_sections)
当试图在 Django 模板中翻译它时,我认为可能是这样的:
{% for section in sections %}
{% with base_angle|add:sections|length|divides:forloop.counter0 as section_angle %}
使用自定义划分过滤器看起来像
def divides(value, param):
return float(param)/float(value)
我对如何安排它、我应该使用的过滤器和参数的顺序有点困惑。对于此处显示的示例,它会导致错误:Caught ValueError while rendering: could not convert string to float:
额外的问题:我试图添加括号来澄清,但模板引擎似乎不喜欢它。