Reputation: 91
I've got this problem. I have a dictionary with keys and values and I want to do this:
Form_url : {u'b4eee942-0ee7-4413-aaab-9cfa9adda905': u'observaciones',
u'79d352f8-d4d1-4d15-a1c8-f68dc1dcc75d': u'OPERADOR TRAINEE',
u'9bf43b36-64bf-456b-a382-b90493797196': u'Puesto al que postula',
u'182af529-c01b-4345-a6b2-14811ff41269': u'ANUAL'}
<table border="0">
{{for elem in form_url:}}
<tr>
{{if elem == '182af529-c01b-4345-a6b2-14811ff41269':}}
<td>TIPO DE EXAMEN :</td>
<td>{{=form_url['182af529-c01b-4345-a6b2-14811ff41269']}}</td>
</tr>
<tr>
{{elif elem == '9bf43b36-64bf-456b-a382-b90493797196':}}
<td>PUESTO AL QUE POSTULA :</td>
<td>{{=form_url['9bf43b36-64bf-456b-a382-b90493797196']}}</td>
</tr>
<tr>
{{elif elem == '79d352f8-d4d1-4d15-a1c8-f68dc1dcc75d':}}
<td>OCUPACION ACTUAL :</td>
<td>{{=form_url['79d352f8-d4d1-4d15-a1c8-f68dc1dcc75d']}}</td>
</tr>
<tr>
{{elif elem == 'b4eee942-0ee7-4413-aaab-9cfa9adda905':}}
<td>OBSERVACIONES :</td>
<td>{{=form_url['b4eee942-0ee7-4413-aaab-9cfa9adda905']}}</td>
{{pass}}
</tr>
{{pass}}
</table>
I want my output to be in order with my html code
Like this:
TIPO DE EXAMEN: ANUAL
PUESTO AL QUE POSTULA: Puesto al que postula
OCUPACION ACTUAL: OPERADOR TRAINEE
OBSERVACIONES: observaciones
this is the exact format in which I want my output, but the real output is:
OBSERVACIONES: observaciones
OCUPACION ACTUAL: OPERADOR TRAINEE
PUESTO AL QUE POSTULA: Puesto al que postula
TIPO DE EXAMEN: ANUAL
which is the order of the dictionary, and not my html
How can I output according to my html and not according to the order in the dictionary?
Disctionaries are not in order so it gives me a random order for every dictionary I create.
Thanks in advance for the help.
Upvotes: 0
Views: 158
Reputation: 168716
Don't use a dictionary -- they aren't ordered:
Form_url = (
(u'182af529-c01b-4345-a6b2-14811ff41269', u'ANUAL')
(u'9bf43b36-64bf-456b-a382-b90493797196', u'Puesto al que postula'),
(u'79d352f8-d4d1-4d15-a1c8-f68dc1dcc75d', u'OPERADOR TRAINEE'),
(u'b4eee942-0ee7-4413-aaab-9cfa9adda905', u'observaciones'),
)
<table border="0">
{{for elem,value in form_url:}}
<tr>
{{if elem == '182af529-c01b-4345-a6b2-14811ff41269':}}
<td>TIPO DE EXAMEN :</td>
<td>{{=value}}</td>
</tr>
...
Or, if you must use a dictionary, don't use a for loop, just emit the table rows in the right order.
# form_url as it is listed in your question.
<tr>
{{if '182af529-c01b-4345-a6b2-14811ff41269' in form_url:}}
<td>TIPO DE EXAMEN :</td>
<td>{{=form_url['182af529-c01b-4345-a6b2-14811ff41269']}}</td>
</tr>
<tr>
{{if '9bf43b36-64bf-456b-a382-b90493797196' in form_url:}}
<td>PUESTO AL QUE POSTULA :</td>
<td>{{=form_url['9bf43b36-64bf-456b-a382-b90493797196']}}</td>
</tr>
...
Upvotes: 1