用django-tagging列出每个帖子的标签

时间:2018-11-23 13:11:59

标签: django tags django-tagging

我使用django-tagging,无法弄清楚如何单独列出和显示每个帖子的标签。

views.py

def news (request):

    haberler = Haberler.objects.all().filter(status=1).order_by('-created')

    #tags = Tag.objects.usage_for_model(Haberler, counts=True) // to list all tags of a model

    return render(request, 'haberler/haberler.html',{'haberler':haberler,
                                                    'tags':tags,
                                                    })

haberler.html

    <div class="col s12 m8 l9 xl9">
        <div class="col s12 grey-text haber-date">{{haberler.created|date:'d/m/Y'}}</div>
        <div class="col s12" style="font-family:Purista Semibold">{{haberler.title}}</div>
        <div class="col s12 haber-icerik"><span class="grey-text text-darken-3">{{haberler.content|safe}}</span></div>
        <div class="col s12" style="margin-top:1rem;">
            <!--<p>{{haberler.tags}}</p>-->
            {% for tag in tags %}   
                <div class="grey lighten-3" style="display:inline; border:thin solid #999;padding:.3rem; font-size:.8rem;border-radius: 3px;">{{ tag.name }}</div>
            {% endfor %}
        </div>
    </div>

{{haberler.tags}} 将相关文章的标签以逗号分隔的字符串形式列出,我无法为每个标签指定样式。

谢谢。

0 个答案:

没有答案