【发布时间】:2016-05-05 21:09:12
【问题描述】:
我正在使用django_tables2 将我的表格更改为datatables。但是,我真的很困惑如何继续进行此操作。我的观点 campaigns.py 我有这个(这个文件有另外 1 个其他类和 2 个方法):
class CampaignListView(FacebookAdInit):
""" CampaignListView for viewing all the campaigns"""
def get(self, request, *args, **kwargs):
ad_account = self.get_ad_account(kwargs.get('ad_account_id'))
campaigns = self.get_campaigns(ad_account.get('id')) \
if ad_account else None
context = {'campaigns': campaigns, 'ad_account': ad_account}
return render(request, 'app/campaigns/index.html', context)
我在模板中将context 字典显示为表格:campaigns/index.html,使用<table>,<td> and <tr> HTML 标签:
<table class="table table-bordered table-striped" id="campaigns">
<thead>
<tr>
<th> #</th>
<th> Campaign Name</th>
<th> Campaign Objective</th>
<th> Campaign Effective Status</th>
</tr>
</thead>
<tbody>
{% for campaign in campaigns %}
<tr>
<td> {{ forloop.counter }} </td>
<td>
<a href="/ad_accounts/{{ ad_account.id }}/campaigns/{{ campaign.id }}/ad_sets">
{{ campaign.name }} </a>
</td>
<td> {{ campaign.objective }}</td>
<td> {{ campaign.effective_status }} </td>
</tr>
{% endfor %}
</tbody>
</table>
现在我到底要如何将它变成一个“分页”数据表。我经历了无数的 SO 问题和this one looked helpful,但是如果我的结构是,我如何将我的视图导入到tables.py 以及在哪里放置tables.py 文件:
folder\
migrations\
static\
templates\
app\
#a whole bunch of templates
views\
campaigns.py
__init__.py
models.py
forms.py
...
...
【问题讨论】:
标签: django datatables django-tables2