Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way to embed HTML in an RSS feed?

Tags:

html

django

rss

I am using Django's RSS capabilities to build an RSS feed. The <description> of the RSS feed items contains HTML markup. Currently, I am just injecting the HTML markup into the feed using the following template:

{{ obj.post }}

Django, of course, translates special characters (<, >, &, etc.) to their respective HTML entities.

I know I could just output the HTML and wrap all the HTML code in <![CDATA[...]]> sections. This page says that either method is acceptable. If that's true, is there a good reason to pick one method over the other? And if I use example #2, is there a filter for Django to automatically wrap the HTML text in CDATA tags, or should I just change my template to:

<![CDATA[
{{ obj.post|safe }}
]]>

Edit

It seems that Django autoescapes special characters in RSS feeds (or any XML for that matter) no matter what, regardless of whether you pass it through the safe filter or not (the issue is discussed in this ticket). However, general answers are welcome.

like image 904
mipadi Avatar asked Jan 14 '09 18:01

mipadi


People also ask

How do I display RSS feeds on my website?

Right click an empty space on the website you'd like an RSS feed for, then click View Page Source (the exact wording may vary depending on your browser). If searching for rss doesn't work, try atom instead. Look for an RSS URL, as you can see above, then copy it into your feed reader.

What is RSS feed in HTML?

RSS is used to share content between websites. With RSS, you register your content with companies called aggregators. So, to be a part of it: First, create an RSS document and save it with an . xml extension. Then, upload the file to your website.

Is it legal to use RSS feeds on your website?

In the United States, the author of any written material generally owns a copyright on that material. Since RSS is merely a way to access that material, the material is still copyrighted. RSS doesn't change anything. Whether you use an RSS tool or a web browser to access material, the material is still copyrighted.

Is RSS feed outdated?

Is it still used online? Yes and no. RSS feeds are certainly still present (more on this later), but they aren't as dominant as they once were. Social media sites like Facebook, Twitter, LinkedIn, and others have become the go-to option for following sites, watching feeds, and learning about the latest content.


1 Answers

When I run into issues like this with Django my first instinct is to run off and find a normal Python lib that does what I want. In this case PyRSS2Gen might be your saviour.

It'll probably require a bit more fannying around (because it'll be unaware of what Django objects are) but it should be raw enough to let you do as you wish.

And if it isn't, it's just a script. You can hack it apart to allow raw HTML if you please =)

like image 154
Oli Avatar answered Nov 10 '22 22:11

Oli