title: django template display python dictionary on a bootstrap table
body: <p>I have a django view that returns this dictionary </p>
  
  <pre><code>args={'Residential': 'N/A', 'School': ('481 address', 600), 'Park': 'N/A', 'Religious': 'N/A', 'Childcare': ('123 address', 5)}
  </code></pre>
  
  <p>I have this code that correctly displays it on the HTML page</p>
  
  <pre><code>&lt;h5&gt;&lt;b&gt;Nearest Childcare Parcel&lt;/b&gt; = {{ Childcare }}&lt;/h5&gt;
  &lt;h5&gt;&lt;b&gt;Nearest Park Parcel&lt;/b&gt; = {{ Park }}&lt;/h5&gt;
  &lt;h5&gt;&lt;b&gt;Nearest Religious Parcel&lt;/b&gt; = {{ Religious }}&lt;/h5&gt;
  &lt;h5&gt;&lt;b&gt;Nearest Residential Parcel&lt;/b&gt; = {{ Residential }}&lt;/h5&gt;
  &lt;h5&gt;&lt;b&gt;Nearest School Parcel&lt;/b&gt; = {{ School }}&lt;/h5&gt;
  </code></pre>
  
  <p>this outputs </p>
  
  <p><a href="https://i.stack.imgur.com/vsVVJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vsVVJ.png" alt="enter image description here"></a></p>
  
  <p>which is okay but its ugly and messy. </p>
  
  <p>I want to nicely put it into a table. </p>
  
  <p>So here is my html code using the django jinja template</p>
  
  <pre><code>&lt;div class="container"&gt;
        &lt;h2&gt;Property Search Results&lt;/h2&gt;
        &lt;table class="table"&gt;
          &lt;thead&gt;
            &lt;tr&gt;
              &lt;th&gt;Layer&lt;/th&gt;
              &lt;th&gt;Address&lt;/th&gt;
              &lt;th&gt;Distance to Property&lt;/th&gt;
            &lt;/tr&gt;
          &lt;/thead&gt;
  
          &lt;tbody&gt;            
            &lt;tr&gt;
              {% if args %}
              &lt;td&gt;Childcare&lt;/td&gt;            
              &lt;td&gt;{ args['Childcare'][0] }&lt;/td&gt;
              &lt;td&gt;{ args['Childcare'][1] }&lt;/td&gt;
              {% endif %}
  
            &lt;/tr&gt;      
            &lt;tr class="success"&gt;
              {% if args %}
              &lt;td&gt;Park&lt;/td&gt;
              &lt;td&gt;{ args['Park'][0] }&lt;/td&gt;
              &lt;td&gt;{ args['Park'][1] }&lt;/td&gt;
              {% endif %}
            &lt;/tr&gt;
            &lt;tr class="danger"&gt;
              {% if args %}
              &lt;td&gt;Religious&lt;/td&gt;
              &lt;td&gt;{ args['Religious'][0] }&lt;/td&gt;
              &lt;td&gt;{ args['Religious'][1] }&lt;/td&gt;
              {% endif %}
            &lt;/tr&gt;
            &lt;tr class="info"&gt;
              {% if args %}
              &lt;td&gt;Residential&lt;/td&gt;
              &lt;td&gt;{ args['Residential'][0] }&lt;/td&gt;
              &lt;td&gt;{ args['Residential'][1] }&lt;/td&gt;
              {% endif %}
            &lt;/tr&gt;
            &lt;tr class="warning"&gt;
              {% if args %}
              &lt;td&gt;School&lt;/td&gt;
              &lt;td&gt;{ args['School'][0] }&lt;/td&gt;
              &lt;td&gt;{ args['School'][1] }&lt;/td&gt;
              {% endif %}
            &lt;/tr&gt;
  
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>there are no errors but nothing gets displayed at all on the table. </p>
  
  <p>What is the best way to get this too work? should I do a for loop through the args dictionary?</p>
  
  <p>this is the entire view</p>
  
  <pre><code>class HomePageView(TemplateView):
      template_name = 'index.html'
      def get(self, request):
          cur = conn.cursor()
          cur.execute("delete from reporter_post")
          form = HomeForm()
          #posts = Post.objects.all()
  
          #args = {'form': form, 'posts': posts}
          return render(request, self.template_name, {'form': form})
  
      def post(self, request):
          form = HomeForm(request.POST)
          print(form)
          if form.is_valid():
              cur = conn.cursor()
              cur.execute("delete from reporter_post")
              form.save()
              g = geocoder.bing(str(form.cleaned_data['address']), key=bingkey)
              try:
                x,y=g.latlng[1],g.latlng[0]
                print(x,y)
                pre_qry='''with a as(select parcelid,owner_name,geom
                                from macomb_parcels_zoning_mun mpzu 
                                where st_intersects(geom,st_transform(st_setsrid(ST_FlipCoordinates(st_makepoint({0}, {1})),4326),102690))
                                )
                        update reporter_post set parcelid=a.parcelid, owner_name=a.owner_name,geom=a.geom from a;
                        '''.format(y,x)
                cur.execute(pre_qry)
                conn.commit()
                qry = '''                                    
                        with address1 as(select '{0}'::text subject_parcel_address, mpzu.*
                                from macomb_parcels_zoning_mun mpzu 
                                where st_intersects(geom,st_transform(st_setsrid(ST_FlipCoordinates(st_makepoint({1}, {2})),4326),102690))
                                 ),
                        process 
                          as(select distinct on(zone_from_parcels,subject_parcel_address) zone_from_parcels,subject_parcel_address,buffered_parcel_address,owner_name,dist
                                from(select aa.address buffered_parcel_address,aa.owner_name,aa.zone_for_buff zone_from_parcels,
                                    round(st_distance(aa.geom,t.geom)::numeric,2 ) dist, t.subject_parcel_address
                                        from mac_parcels_union aa
                                        cross join lateral (
                                            select m.geom,m.subject_parcel_address, mbu.geom geom_buff 
                                            from address1 m join mac_buffer_union mbu on st_dwithin(m.geom,mbu.geom,2000)
                                                where mbu.parcelid = aa.parcelid and aa.parcelid &lt;&gt; m.parcelid 
                                            )t
                                    group by buffered_parcel_address,owner_name,zone_from_parcels,dist,subject_parcel_address
                                    order by dist) t
                            order by subject_parcel_address,zone_from_parcels,dist
                            )
                      SELECT zone_from_parcels zone_,subject_parcel_address,buffered_parcel_address,owner_name,dist::integer 
                                  FROM process
                            '''.format(str(form.cleaned_data['address']), y, x)
                cur.execute(qry)
                row=cur.fetchall()
                print(row)
                if not row:
                    return render(request, self.template_name, {'form': form,'text': 'N/A'})
                else:
                    zones={'Childcare': 'N/A', 'School': 'N/A', 'Park': 'N/A', 'Residential': 'N/A', 'Religious': 'N/A'}
                    for x in row:
                        for k, v in zones.items():
                            if x[0] == k:
                                print(k, x[0])
                                zones[k] = x[2], x[4]
  
  
                    args = {'form': form, 'Residential': zones['Residential'],
                            'School': zones['School'], 'Religious': zones['Religious'],
                            'Childcare': zones['Childcare'], 'Park': zones['Park']}
                    return render(request, self.template_name, args)
                    print args
              except:
                args={'Residential': 'N/A', 'School': ('481 address', 600), 'Park': 'N/A', 'Religious': 'N/A', 'Childcare': ('123 address', 5)}
                return render(request, self.template_name, args)
  </code></pre>