0

According to this question, If items(), keys(), values(), iteritems(), iterkeys(), and itervalues() are called with no intervening modifications to the dictionary, the lists will directly correspond.

However in Jinja2 this seems not to be the case, as keys() and values() are giving different orders for me. I'm trying to build a table as follows:

   {% for record in records %}
        {% if loop.first %}
            <tr>
            {% for key in record.keys() %}
                <th>{{ key }}</th>
            {% endfor %}
            </tr>
        {% endif %}
        <tr>
        {% for value in record.values() %}
            <td>{{ value }}</td>
        {% endfor %}
        </tr>
    {% endfor %}

and currently the values don't correspond to the keys. Anyone else come across this?

Community
  • 1
  • 1
tdc
  • 8,219
  • 11
  • 41
  • 63

1 Answers1

0

Seems the problem was actually with psycopg.extras.DictCursor2. In the end I used an OrderedDict as suggested by hiro.

tdc
  • 8,219
  • 11
  • 41
  • 63