I've followed few tutorials (bottle one as well), but my code ain't working as supposed to. Basically I'd like to have a html table generated in this way:
template is served in this way:
return template('template', data=result)
Snippet of code from my template:
%for item in data.data:
%if ("X" in c_label and "Y" not in p_label and "Z" not in p_label):
<tr>
<td>{{child}}</td>
<td>{{parent}}</td>
</tr>
%elif ("X" in c_label and "Y" in p_label):
<tr>
<td>{{child}}</td>
<td>{{parent}}</td>
</tr>
%elif ("X" in c_label and "Z" in p_label):
<tr>
<td>{{child}}</td>
<td>{{parent}}</td>
</tr>
%elif "W" in c_label:
<tr>
<td>{{child}}</td>
<td>{{parent}}</td>
</tr>
%elif "U" in c_label:
<tr>
<td>{{child}}</td>
<td>{{parent}}</td>
</tr>
%elif "Z" in c_label:
<tr>
<td>{{child}}</td>
<td>{{parent}}</td>
</tr>
%end
</table>
The problem is that python keeps running the for
cycle even after %end
. I've seen it in the generated page:
<table>
<tr>
<td>U</td>
<td>I</td>
</tr>
</table>
<tr>
<td>X</td>
<td>U</td>
</tr>
</table>
<tr>
<td>U</td>
<td>I</td>
</tr>
</table>
So for some reason it keeps ammending the </table>
per each iteration which ofc totally screws the final page :).
Thanks in advance!
Peter
Thanks to kwinkunks I've identified this as a SimpleTemplate engine.
The answere is here: http://bottlepy.org/docs/0.11/stpl.html
e.g:
<div>\\
%if True:
<span>content</span>\\
%end
</div>
So as kwinkunks suggested, if
must be ended with end
as well.