title: My defaultdict(list) won't show up on template but does in my view
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/4764110/django-template-cant-loop-defaultdict">Django template can’t loop defaultdict</a>  </p>
  </blockquote>
  
  
  
  <p>I am wondering why my <code>defaultdict(list)</code> will show when I test it in my views.py but when I go to show the data on my template, I get nothing, not even an error.</p>
  
  <p>Any suggestions?</p>
  
  <p>Here is my views.py - confirm_list is my defaultdict(list)</p>
  
  <pre><code>def confirmations_report(request, *args, **kwargs):
  from investments.models import Investment, InvestmentManager
  from reports.forms import ConfirmationsForm
  from collections import defaultdict
  import ho.pisa as pisa
  import cStringIO as StringIO
  import os.path
  confirm_list = defaultdict(list)
  context = {}
  
  if request.POST:
      form = ConfirmationsForm(request.POST)
      if form.is_valid():
          start_date = form.cleaned_data['start_date']
          end_date = form.cleaned_data['end_date']
          investments = Investment.objects.all().filter(contract_no = "",maturity_date__range=(start_date, end_date)).order_by('financial_institution')
          for i in investments:
              confirm_list[i.financial_institution.pk].append({
                  'fi':i.financial_institution,
                  'fi_address1': i.financial_institution.address1,
                  'fi_address2': i.financial_institution.address2,
                  'fi_city': i.financial_institution.city,
                  'fi_prov': i.financial_institution.state_prov,
                  'fi_country': i.financial_institution.country,
                  'fi_postal': i.financial_institution.postal,
                  'primary_owner': i.plan.get_primary_owner().member,
                  'sin': i.plan.get_primary_owner().member.client.sin,
                  'type': i.product.code,
                  'purchase_amount': i.amount,
                  'purchase_date': i.start_date,
              })
              context['investments'] = investments
          context['confirmlist'] = confirm_list
          for key, value in confirm_list.items():
              print key, value
          context['inv'] = investments
      if request.POST.has_key('print_report_submit'):
          context['show_report'] = True
          context['mb_logo'] = os.path.join(os.path.dirname(__file__), "../../../media/images/mb_logo.jpg")
          html = render_to_string('reports/admin/confirm_report_print.html', RequestContext(request,context))
          result = StringIO.StringIO()
          pdf = pisa.pisaDocument(StringIO.StringIO(html.encode("ISO-8859-1")), result)
          response = HttpResponse(result.getvalue(), mimetype='application/pdf')
          response['Content-Disposition'] = 'attachment; filename=unreceived-confirmations.pdf'
          return response
  
  else:
      form = ConfirmationsForm()
  
  context['form'] = form
  return render_to_response('reports/admin/confirm_report.html', RequestContext(request, context))
  </code></pre>
  
  <p>But when I do:</p>
  
  <pre><code>for key, value in confirm_list.items():
              print key, value
  </code></pre>
  
  <p>On my template like so:</p>
  
  <pre><code>{% extends 'reports/admin/base.html' %}
  {% load humanize %}
  
  {% block report_html %}
  &lt;h3&gt;Unreceived Confirmations Report&lt;/h3&gt;
  &lt;form method="post" action=""&gt;
  &lt;table&gt;
      &lt;tr&gt;
          &lt;td&gt;
              &lt;strong&gt; {{ form.start_date.label }}&lt;/strong&gt; {{ form.start_date }}
              &lt;strong&gt;{{ form.end_date.label }}&lt;/strong&gt; {{ form.end_date }}
          &lt;/td&gt;
      &lt;/tr&gt;
  &lt;/table&gt;
  &lt;input type="submit" value="View Report"&gt;
      &lt;input type="submit" name="print_report_submit" value="Print Report"/&gt;
  &lt;/form&gt;
      {% for key, value in confirmlist.items %}
          {{ key }} - {{ value }}
      {% endfor %}
  {% endblock %}
  </code></pre>
  
  <p>I get nothing.</p>
  
  <p>Here is a sample of the output I get when testing in the views.py</p>
  
  <pre><code>33 [{'fi_address1': u'Scotiabank FAS', 'fi_country': u'Canada', 'fi_address2': u'20 Queen Street West, Suite 2600', 'fi_city': u'TORONTO', 'fi': &lt;FinancialInstitution: NATIONAL TRUST&gt;, 'fi_prov': u'Ontario', 'fi_postal': u'### ###', 'purchase_amount': Decimal('30000.00'), 'purchase_date': datetime.date(2011, 6, 27), 'type': u'GIC', 'sin': u'###/###/###', 'primary_owner': &lt;Member: #, #&gt;}]
  </code></pre>