feeds - RSS feed parsing using feedparser

Tags which can retrieve and parse RSS and Atom feeds, and return the results for use in templates.

Based, in part, on the original idea by user baumer1122 and posted to djangosnippets at http://www.djangosnippets.org/snippets/311/

native_tags.contrib.feeds.include_feed(feed_url, *args)

Parse an RSS or Atom feed and render a given number of its items into HTML.

It is highly recommended that you use Django’s template fragment caching to cache the output of this tag for a reasonable amount of time (e.g., one hour); polling a feed too often is impolite, wastes bandwidth and may lead to the feed provider banning your IP address.

Arguments should be:

  1. The URL of the feed to parse.
  2. The name of a template to use for rendering the results into HTML.
  3. The number of items to render (if not supplied, renders all items in the feed).

The template used to render the results will receive two variables:

items
A list of dictionaries representing feed items, each with ‘title’, ‘summary’, ‘link’ and ‘date’ members.
feed
The feed itself, for pulling out arbitrary attributes.

Requires the Universal Feed Parser, which can be obtained at http://feedparser.org/. See its documentation for details of the parsed feed object.

Syntax:

{% include_feed [feed_url] [num_items] [template_name] %}

Example:

{% include_feed "http://www2.ljworld.com/rss/headlines/" 10 feed_includes/ljworld_headlines.html %}

This is a function tag.

native_tags.contrib.feeds.parse_feed(feed_url)

Parses a given feed and returns the result in a given context variable.

It is highly recommended that you use Django’s template fragment caching to cache the output of this tag for a reasonable amount of time (e.g., one hour); polling a feed too often is impolite, wastes bandwidth and may lead to the feed provider banning your IP address.

Arguments should be:

  1. The URL of the feed to parse.

Requires the Universal Feed Parser, which can be obtained at http://feedparser.org/. See its documentation for details of the parsed feed object.

Syntax:

{% parse_feed [feed_url] as [varname] %}

Example:

{% parse_feed "http://www2.ljworld.com/rss/headlines/" as ljworld_feed %}

This is a function tag.

Previous topic

hash - MD5 and SHA tags

Next topic

gchart - Google Charts via GChartWrapper

This Page