3

I'm trying to return multiple arrays from my views file in Django. Here is my current attempt:

views.py:

qb =[] #some array with objects
qb1 =[] #some array with objects
qb2 = [] #some array with objects

return render_to_response('qb.html', {'qb' : qb}, {'qb1': qb1}, {'qb2' : 'qb2'})

And in my templates\qb.html, I have some tables set up like so:

     {% for p in qb %}
        <tr>
            <td>{{p.player.last_name}}</td>
            <td>{{p.player.first_name}}</td>

        </tr>
     {% endfor %}
     {% for p in qb1 %}
        <tr>
            <td>{{p.player.last_name}}</td>
            <td>{{p.player.first_name}}</td>

        </tr>
     {% endfor %}
     {% for p in qb2 %}
        <tr>
            <td>{{p.player.last_name}}</td>
            <td>{{p.player.first_name}}</td>

        </tr>
     {% endfor %}

Now what I had before (which worked) was just returning one array (namely qb) and then having one table which iterated over qb so I know my previous code was right and I just ended on taking two more arrays and then it crashed on the page saying:

AttributeError at /qb/
'dict' object has no attribute 'push'

On the webpage with an error here:

return render_to_response('qb.html', {'qb' : qb}, {'qb1': qb1}, {'qb2' : 'qb2'})

So basically my question is how can I return multiple arrays and reference them in html file using Django?

Grimthorr
  • 6,856
  • 5
  • 41
  • 53

0 Answers0