I'm just learning Jinja2. I have never done any templating before so I find the documentation very confusing right now.
How do I do build up a HTML table with a simple FOR loop? My template looks something like this:
{% for item in items %}
<TR>
<TD class="c1"><IMG src="favicon.ico"></TD>
<TD class="c2">{{date}}</TD>
<TD class="c3">{{id}}</TD>
<TD class="c4"><SPAN>{{position}}</SPAN></TD>
<TD class="c5"><SPAN>{{status}}</SPAN></TD>
</TR>
{% endfor %}
My python code looks like this:
import jinja2
loader = jinja2.FileSystemLoader('./index.html')
env = jinja2.Environment(loader=loader)
template = env.get_template('')
print template.render(date='2012-02-8', id='123', position='here', status='Waiting')
I can't seem to generate any tables. I also don't know if this is the best way to populate a table with several fields.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…