我试图将我的django应用中的表格转换为datatables using django-tables2。
我的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)
视图我有:
campaigns/index.html
我的{% extends "app/empty_page.html" %}
{% load render_table from django_tables2 %}
{% block content %}
{% if ad_account %}
{% render_table context %}
{% endif %}
{% endblock %}
我有:
Expected table or queryset, not 'str'.
然而,这给了我错误: <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>
非常感谢您的帮助。
现在我使用这段代码生成表格:
$ML_Subscribers = new MailerLite\Subscribers('xxxxxxxxxxxxxxxxxxxxxx');
$subscriber = array(
'email' => $e,
'name' => $f,
);
$subscriber = $ML_Subscribers->setId('xxxxxxxxxxx')->setAutoresponders(false)->add($subscriber);
答案 0 :(得分:1)
您应该将Table
实例或查询集传递给render_table
代码。
{% render_table campaigns %}