我试图从查询结果存储在一个列表或类似(尝试不同的选择)的列表,而是一个我已经拿到了与最远的是:Django的遍历对象的模板
def index(request):
for post in blog_posts:
comments_total.setdefault(post.id, []).append(comments.total(post.id))
return render_to_response('blog/index.html', {
'comments': comments_total})
在返回数据,我得到: {5L:[2],6L:[1]}
我使用这个代码访问:
{% if comments %}
{{comments}}<br />
{% for cid in comments %}
{% if cid == post.id %}
{{cid}} - {{comments.cid.0}}<br />
{{cid}} - {{comments.6.0}}
{% endif %}
{% endfor %}
{% endif %}
什么它打印出全部是:
{5L:[2],6L:[1]} 5 - 5 - 1
是否有如何让所有意见,在这种情况下,博客的替代,算上通过每篇文章的结果并将其返回给模板?
我想要做的是得到一个博客的开始页的计数器。 “你有(X)对这篇文章的评论” - 事物的种类。
您正在使用您的评论系统,任何特定的模块?其中一些(如Disqus)已经内置了用于返回这种信息的函数。 – woemler
没有额外的模块。我拥有的唯一模块是我为评论和帖子所做的定制,它非常简单,“将它整齐地加载到数据库中”。 –