![](/img/trans.png)
[英]Django template is removing html table, regardless of using safe or autoescape
[英]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.