Django Remote Include and RSS to HTML Template Tags

PDF versionPDF version

I wrote some pretty cool template tags last night for Django.  One that you can use to include the content of a remote URL into a template, and another that pulls down an RSS/Atom feed and writes it out as CSS classed HTML.

Both of them can run in simple or cached mode.  In cached mode, they cache the results for a specified amount of time in seconds.

Here are the tags:

remote_include.py

rss2html.py

The rss2html.py tag requires the Universal Feed Parser in the same directory as rss2html.py or at least on the python path.

Here is a template example for using both tags:

<html>
  <head>
    <titleTemplate Tag Testing</title>
  </head>
  <body>
    <h1>Remote Include - No caching</h1>
    {% sri http://carsongee.com/ %}
    <h1>Remote Include - Caching for One Hour</h1>
    {% cri http://carsongee.com/ 3600 %}
    <h1>RSS 2 HTML - No Caching</h1>
    {% rss2html http://carsongee.com/rss.xml %}
    <h1>RSS 2 HTML - Caching for One Hour</h1>
    {% rss2htmlcache http://carsongee.com/rss.xml 3600 %}
    <h1>RSS 2 HTML - Caching or Not - Specify Number of Entries</h1>
    {# Grab first 3 entries #}
    {% rss2html http://carsongee.com/rss.xml 3 %}
    {% rss2htmlcache http://carsongee.com/rss.xml 3600 3 %}
  </body>
</html>

That is pretty much all there is to it. Let me know in the comments if you have any issues.

 

 
 

Reply

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters (without spaces) shown in the image.