2016-05-05 11 views
-1

を使用してテーブルをdatatablesに変更しています。しかし、私はこれをどうやって進めるのか、本当に混乱しています。私の見解campaigns.pyイム私はこれ(このファイルは2つの方法で、他の1、他のクラスがあります)があります。<table>,<td> and <tr> HTMLタグを使用してcampaigns/index.html::私は私のテンプレート内のテーブルとしてcontext辞書を表示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) 

<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 
... 
... 

答えて

0

あなたはコードでジャンゴ・tables2を使用していないように見えますあなたは投稿しました:独自のテーブルテンプレートを実行していますが、django-tables2を使用する意図はありません。

Django-table2は、datatables-instanceにデータを提供するためのものでもありません。それは動作するかもしれませんが、静的なHTMLテーブルを生成することを意図していました。

関連する問題