开发者

Django TemplateSyntaxError Could not parse the remainder: '()'

开发者 https://www.devze.com 2023-02-15 06:48 出处:网络
I\'m trying to iterate a dictionary of dictionary in Django template page {% for (key_o, value_o) in f_values.items() %}

I'm trying to iterate a dictionary of dictionary in Django template page

       {% for (key_o, value_o) in f_values.items() %}
            <tr class="row {% cycle 'odd' 'even' %}">
                {% for (key_i, val_i) in value_o.items() %}
                    <td class="tile ">
                        {{ val_i }} 
                    </td>
                {% endfor %}    
            </tr>
        {% endfor %}

But getting the error

TemplateSyntaxError at /tree/branches/
Could not parse the remainder: '()' from 'f_values.items()'

What is causing the error?

--update

This is how i creating the f_values

        columnValues = []
        for idx_o, val_o in enumerate(results['values']):
            columnValues[idx_o] = {}
            for idx_i, val_i in enumerate(val_o):
                columnValues开发者_如何学Go[idx_o][idx_i] = {}
                columnValues[idx_o][idx_i]['value'] = val_i
                name = columnNames[idx_i]
                columnValues[idx_o][idx_i]['name'] = name
                columnValues[idx_o][idx_i]['format'] = {}
                for val_f in formats:
                    if (name == val_f.Header) :
                        columnValues[idx_o][idx_i]['format']['LowerLimit'] = val_f.LowerLimit



data = {
        'f_values': columnValues,             
       }


You don't need to use () to call methods in templates, you can just use f_values.items. This notation works for lists, tuples, and functions.

For example, if you have these Python values:

    lst = ['a', 'b', 'c']
    di = {'a': 'a'}
    class Foo:
       def bar(self): pass
    foo = Foo()

in your template, you can access them like this:

    {{ lst.0 }}
    {{ di.a }}
    {{ foo.bar }}

For your code:

      {% for (key_o, value_o) in f_values.items %}
            <tr class="row {% cycle 'odd' 'even' %}">
                {% for (key_i, val_i) in value_o.items %}
                    <td class="tile ">
                        {{ val_i }} 
                    </td>
                {% endfor %}    
            </tr>
        {% endfor %}
0

精彩评论

暂无评论...
验证码 换一张
取 消