mengu on web programming.

Generating RSS Feeds With WebPy

Some days ago I have seen someone asking how to generate RSS feeds with [webpy](http://www.mengu.net/tag/webpy). It is like generating feeds with any other web framework. How the logic should be? * Retrieve the items from the database. * Create a RSS template. * Set the content type. * Print the items via template. So, let's start with creating our feed class first. class feed: def GET(self): date = datetime.today().strftime("%a, %d %b %Y %H:%M:%S +0200") posts = db.select("post", order="id DESC", limit=10) web.header('Content-Type', 'application/xml') return render.feed(posts=posts, date=date) This is all we need for generating for the feed. Now we can skip to create the feed template. Mengu.net RSS Feed http://www.mengu.net/ mengu on web programming. en-us {{ date }} {{ date }} Mengu.net mengu@mengu.net mengu@mengu.net {% for post in posts %} {{ post.title }} http://www.mengu.net/post/{{ post.slug }} {{ post.dateline }} http://www.mengu.net/post/{{ post.dateline }} {% endfor %} This is a valid RSS feed. You can learn more on RSS feeds [here](http://cyber.law.harvard.edu/rss/rss.html). So, basically I have created a valid RSS template and then loop through the post items and I have my RSS working perfect. Enjoy!
Check my latest project compector.com where you can post references about your former employers and see what others have said about the future employers. Sign up now and post a reference and share it on twitter or facebook.

Comments

Ken said on 05/02/2010 08:56 AM
front of the render, it needs: web.header('Content-Type', 'application/xml')

Mengu Kagan said on 05/02/2010 19:25 PM
Thank you Ken. I forgot changing the content type. It's needed because if it's going to be a valid RSS feed, the content type should be application/xml.

Leave a Response

No HTML allowed. You can use markdown.
Name*:
E-Mail* (not published):
Web site:
Response: