开发者

How to restrict elements in Django templates?

template:

{% for c in feed.comment_set.all reversed %}
  <b>{{c.msg}}</b>
{% endfor %}

Question 1: Here I want only recent 3 commen开发者_如何学Pythonts to be shown. How do I limit the comments.

Question 2: How to add a 'show more' button which will load the remaining comments?

Thanks.


There is a builtin template filter slice that you can use to only show 3 entries of a longer list.

But as your question is tagged with jquery anyway you could probably try a plugin like showMore, that seems to be the exact fit for your problem.

If you want to tailor you own solution look at this answer. Though it uses php the basic logic should be the same and adaptable to Django.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜