簡體   English   中英

使用Django模板到HTML表

[英]Using django template to html table

我想設計一個可以按年相互比較的表。

我的數據是這樣的:

圖書數據圖片

# views.py
def bybook(request, bookName='A-Book'):
    bookdata = models.bookdb.objects.filter(bookName=bookName).order_by('Year', 'point')
    return render(request, 'book.html', locals())

我希望結果想要:

在此處輸入圖片說明

我嘗試過的Django模板重新組合https://docs.djangoproject.com/en/2.0/ref/templates/builtins/#regroup

但無法達到我的要求。

在Django模板中

#first we create the header of the table with the years
<tr class="first-table-row">
        # leave it blank so the first column is empty
        <th></th>
        #loop trough the items
        {% for i in bookdata %} 
           <th>{{i.year}}</th>
        {% endfor %}
</tr>
#loop trough the items again
{% for i in bookdata %}
       <td>{{i.point}}</td>
        # I don't know how your object is structured man please submit it so I can continue 
{% endfor %}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM