如何将我的html表分解为块django python

时间:2016-08-30 13:02:18

标签: python django python-2.7

所以例如我有一个包含3行和100列的表。我想要做的是将它分成几十,这样第一个表有3行,然后是10列,依此类推,直到我有10个表,所有表都有3行和10列。问题是我不想重复,所以在表1中它应该是1-10然后表2它应该是11-20,依此类推等等...

非常感谢任何帮助。我想用python方式而不是css来做这个。

这是我的看法。

@login_required
def shipping_pdf(request, id):
  sheet_data = Sheet.objects.get(pk=id)
  work_order = sheet_data.work_order
  purchase_order = sheet_data.purchase_order
  drawing = sheet_data.drawing_number
  draw_rev = sheet_data.drawing_revision
  part = sheet_data.part_number
  part_rev = sheet_data.part_revision
  customer_data = Customer.objects.get(id=sheet_data.customer_id)
  customer_name = customer_data.customer_name 
  title_head = 'Shipping-%s' % sheet_data.work_order
  complete_data = Sheet.objects.raw("""select s.id, d.id d_id, s.work_order, d.target, i.reading, d.description, i.serial_number from app_sheet s left join app_dimension d on s.id = d.sheet_id
  left join app_inspection_vals i on d.id = i.dimension_id where s.id = %s""" % id)

  for c_d in complete_data:
    dim_description = Dimension.objects.filter(sheet_id=c_d.id).values_list('description', flat=True).distinct()

    dim_id = Dimension.objects.filter(sheet_id=c_d.id)[:1]
    for d_i in dim_id:
      dim_data = Inspection_vals.objects.filter(dimension_id=d_i.id)
      reading_data = Inspection_vals.objects.filter(dimension_id=d_i.id)      

  key_list = []
  vals_list = []

  for xr in complete_data:

    key_list.append(xr.description)
    vals_list.append(xr.reading)

    #print reading_desc
    sample_size = dim_data  
  reading_desc = {} 
  for i in range(len(key_list)):
    if key_list[i] in reading_desc:
      reading_desc[key_list[i]].append(vals_list[i])
    else: 
      reading_desc[key_list[i]]=[vals_list[i]]

      print reading_desc
  return render_to_pdf(
     'app/shipping_pdf.html',  
     {
       'work_order': work_order, 
       'sample_size': sample_size,
       'customer_name': customer_name,
       'title': title_head, 
       'reading_desc': reading_desc, 
       'purchase_order': purchase_order,
       'drawing': drawing,
       'draw_rev': draw_rev,
       'part': part,
       'part_rev': part_rev,

    }                     
  )

这是我的HTML。

      <table style="border: 2px solid black;">
        <thead>
        <tr>
          <th>Serial Number</th>
          {% for ss in sample_size %}
             <th>{{ ss.serial_number }}</th>
          {% endfor %}
        </tr>
        </thead>
        <tbody>
           {% for key, values in reading_desc.items %}
           <tr> 
             <td>{{key}}</td>
             {% for v in values %}
               <td>{{v}}</td>
             {% endfor %}
          </tr>
           {% endfor %}
        </tbody> 
      </table>

这就是现在的样子*注意它全部被压扁了。

Before

这就是我希望它的样子。

enter image description here

尝试了一个仍然没有运气的建议现在我有了新的错误

      <table style="border: 2px solid black;">
        <thead>
        <tr>
          <th>Serial Number</th>
          {% for ss in sample_size %}
             <th>{{ ss.serial_number }}</th>
          {% endfor %}
        </tr>
        </thead>
        <tbody>
           {% for i in range(10) %} 
             {% for j in range(100) %} 
               {% for key, values in reading_desc.items.i*j %}
               <tr> 
                 <td>{{key}}</td>
                 {% for v in values %}
                   <td>{{v}}</td>
                 {% endfor %}
               </tr>
               {% endfor %}
             {% endfor %}
           {% endfor %}
        </tbody> 
      </table>

无法解析余数:'(100)'来自'range(100)'

0 个答案:

没有答案