Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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[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,                     } 
like image 332
Mithun Sreedharan Avatar asked Mar 08 '11 10:03

Mithun Sreedharan


1 Answers

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 %} 
like image 131
Daniel Dinu Avatar answered Sep 20 '22 09:09

Daniel Dinu