辞書のリストをHTMLテーブルとしてdjangoに保存して、django_tables2で使用できるようにします。これについては、何が最善の方法でしょうか?今、私はこれを持っている:辞書のリストをHTMLテーブルとして保存
は私view.py
:
context = {'campaigns': campaigns, 'ad_account': ad_account}
return render(request, 'index.html', context)
:それだけでテーブルを受け入れるため
[<Campaign> { "effective_status": "PAUSED", "id": "6038662580877", "name": "test22", "objective": "APP_ENGAGEMENT" }, <Campaign> { "effective_status": "PAUSED", "id": "6038659889677", "name": "just a test", "objective": "APP_ENGAGEMENT" }]
私はdjango_tablesで私の現在のメソッドを使用傾けます。私が今行っていることは、以下に貼り付けられ、より多くのデータが追加されるにつれて実現不可能な1ページに全体のテーブルを生成します。
<table class="table table-bordered table-striped" id="campaigns">
<thead>
<tr>
<th> #</th>
<th> Name</th>
<th> Objective</th>
<th> Effective Status</th>
</tr>
</thead>
<tbody>
{% for campaign in campaigns %}
<tr>
<td> {{ forloop.counter }} </td>
<td>
<a href="/ad/{{ ad.id }}/campaigns/{{ campaign.id }}/ad_sets">
{{ campaign.name }} </a>
</td>
<td> {{ campaign.objective }}</td>
<td> {{ campaign.effective_status }} </td>
</tr>
{% endfor %}
</tbody>
</table>
個人的に私は人々がDjangoですべての種類のライブラリを使用する理由を知りません。 Djangoには、必要な機能のほとんどが組み込まれています。これらのライブラリの多くは、人生をもっと難しくしています。 – e4c5
ですが、djangoにはデータテーブル機能が組み込まれていません。 – newkid101
Django-tables2のドキュメントはここで役立ちます:http://django-tables2.readthedocs.io/en/latest/pages/table-data.html – Thtu