Frage

I am using mako for creating html templates.

I my template, I have the following code:

% for s in query['sandboxes']:
% for node in s['nodes']:

<table>
<tr>

<td>${node['node_name']}</td>
<td>${node['slowcall_count']}) / ${s['slowcall_count']}</td>

</tr>    
</table>

% endfor
% endfor

The loop and display are working, but it displays "30 / 100" instead of the actual division result.

After searching, I saw this Using from __future__ import in Mako template

and then tried this code:

<td>
<%! 
float(${node['slowcall_count']}) / float(${s['slowcall_count']}) 
%>

but it gives me a syntax error. The follwoing doesn't give any error, but it doesn't display anything either:

<td>
<%! 
float(1) / float(2)
%>

Is there a way to make my division work?

War es hilfreich?

Lösung

This should work between the td tags:

${float(node['slowcall_count']) / float(s['slowcall_count']) }

An expression can occur inside the ${}. As explained here:

http://docs.makotemplates.org/en/latest/syntax.html#expression-substitution

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top