How to create proper RSS feed with HTML content?

Hi!

I am trying to create RSS feed for my blog but while the basics are working fine I don’t know how to handle the actual content. I am using a template set with the description_template that renders title and html content below it. The HTML content is escaped, shows correctly un-escaped but is not rendered as HTML.

You can see here - https://nemecek.be/blog/feed/rss - why I am seeking help with the feed :smiley:

I did not even manage to find many tutorials about creating RSS feeds with Django. They are either very old or show just the basics.

I am also having an issue with author name that is not showing up in the RSS readers.

Here is my complete feeds.py:

class BlogPostsFeed(Feed):
title = "Filip Němeček Blog"
link = "https://nemecek.be/blog/swift-and-ios"
description = "iOS & Swift posts from blog"
author_name = "Filip Němeček"

description_template = 'rss_feed.html'

def items(self):
    return BlogPost.objects.filter(category_id=1).order_by('-created')

def item_title(self, item):
    return item.title

def item_pubdate(self, item):
    return item.created

def categories(self):
    return "Swift", "iOS", "development",

Many thanks for help or pointers!

1 Like

So through a lot of trial and error I got it working correctly. Here is my final template:


{% autoescape off %}
<![CDATA[
{{ obj.title }}

{{ obj.html_content|safe }}
]]
{% endautoescape %}

Probably not the best solution but it works and I am really hesitant to touch it again :smiley:

I’m not sure about your exact problems but you can use https://validator.w3.org/feed/ to validate your feed is correctly formatted. I’m not sure CDATA is normally needed, I don’t use it in my atom feed (which is made with Jekyll, not Django).