如何在Django模板中显示数组

时间:2018-12-29 03:14:40

标签: django-templates

我正在使用Django 2.09 而且我无法在模板中显示我的列表 这是我的代码

Linux服务器,python 3.6

view.py--------------------
  .......
        friends_counter = {}
        index = 0
        for a_campaign in campaigns:
            cnt = 0          
            friends_counter[str(index)] = str(cnt)            
            for a_friend in friends:
                for a_friend_campaign in a_friend.get_newsfeed_campaigns():
                    if(a_friend_campaign  == a_campaign):
                        cnt+=1
                        break
            friends_counter[str(index)] = str(cnt)
            index+=1


        print(friends_counter)   
        context['campaigns'] = campaigns
        context['friends_counter'] =friends_counter
        return context
  template.html----------------
 {% for campaign in campaigns %}
    {{ campaign.name | truncatechars:20 }}
        <div class="font-weight-bold mb-2">
       {% with forloop.counter0 as cnt %}
        {{ friends_counter.cnt }}
        </div>{% endwith %}
{% endfor %}

请帮助我,谢谢!

0 个答案:

没有答案