python - Using multiple for tags in tables with django -


i'm new django, , working on project have items appended multiple lists , display them in table. using tag there quite few items in each list. however, when run code, first item on list repeats on , over, second item repeats on , over, , on. have feeling because used multiple tags. heres code:

<table> {% x in result.netincomear %} {% y in result.d2 %}     <tr>         <td>{{ x }}</td>     <td>{{ y }}</td> </tr> {% endfor %} {% endfor %} </table> 

any ideas went wrong? thanks.

the inner loop should use outer loop variable:

{% x in result.netincomear %}     {% y in x.d2 %}  

upd (after looking @ result variable):

you need change result variable passed template, use zip() join 2 lists:

result = zip(df['date'], df['net income']) return render_to_response('ui/search.html', {"result": result},  context) 

then, in template iterate on result way:

<table>     {% x in result %}     <tr>             <td>{{ x.0 }}</td>         <td>{{ x.1 }}</td>     </tr>     {% endfor %} </table> 

Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -