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

I am using the features of Django RSS to create an RSS feed. The <description> element of RSS feed elements contains HTML markup. I am currently just embedding HTML markup in the feed using the following template:

 {{ obj.post }} 

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

I know that I can simply output HTML and wrap all the HTML in <![CDATA[...]]> . This page says that any of these methods is acceptable. If true, is there a good reason to choose one method over another? And if I use example # 2, is there a filter for Django to automatically bind HTML text in CDATA tags or do I just need to change my template to:

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

Edit

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

+6
html django rss
source share
3 answers

When I run into problems like this with Django, my first instinct is to run away and find the regular Python library that does what I want. In this case, PyRSS2Gen may be your savior.

It will probably take a bit more fannying (because it will not know what Django objects are), but it should be raw enough to allow you to do as you wish.

And if it is not, it is just a script. You can hack it separately to allow raw HTML if you wish =)

+2
source share

Instead of writing your own RSS feed, consider using the Django syndication framework with django.contrib.syndication :

https://docs.djangoproject.com/en/dev/ref/contrib/syndication/

+1
source share

HTML embedding is what CDATA has bothered me in the past. The hopes of RSS readers have evolved to handle such attachments.

0
source share

All Articles