1

im doing something with feedparser: i have a templatetag for display "news" in my home page, but , how ill limit the feedparser result?

inclusion tag

from django.template import Template, Library
import feedparser
register = Library()

@register.inclusion_tag('rss_render.html')
def rss_render(object): #RSS URL "object"
    rss = feedparser.parse(object)       
    return {'rss': rss}

template

<ul>
{% for r in rss.entries %}
<li> <a href="{{ r.link }}" target="_blank" title="{{ r.title }}">{{ r.title }}</a></li>
{% endfor %}
</ul>
Asinox
  • 6,747
  • 14
  • 61
  • 89
  • 1
    I do apologise, not strictly a keyword, but I still find using object as a variable name not a good practice. – Davor Lucic Sep 15 '10 at 21:28

2 Answers2

0

Take this Django snippet for example.

Davor Lucic
  • 28,970
  • 8
  • 66
  • 76
0

You can use Django's slice template tag:

{% for r in rss.entries|slice:":10" %}

http://docs.djangoproject.com/en/dev/ref/templates/builtins/#slice

Kurt McKee
  • 1,410
  • 13
  • 17