How do I write HTML code in Django's syndication feed framework?

I'm using Django's syndication feed framework to generate RSS for my website, referring to this document

I have done the work according to the example it provides, the code is similar to the following, I have not made too many changes.

from django.contrib.syndication.views import Feed
from django.urls import reverse
from policebeat.models import NewsItem

class LatestEntriesFeed(Feed):
    title = "Police beat site news"
    link = "/sitenews/"
    description = "Updates on changes and additions to police beat central."

    def items(self):
        return NewsItem.objects.order_by('-pub_date')[:5]

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

    def item_description(self, item):
        return item.description

    # item_link is only needed if NewsItem has no get_absolute_url method.
    def item_link(self, item):
        return reverse('news-item', args=[item.pk])

Then I want to add <a href="test.com">Click to my site</a> in item_description, I made some minor changes.

    def item_description(self, item):
        description = item.article_description
        description = description + "<a href='test.com'>Click to my site</a>"
        return description

But the final generated code is escaped.

<description>&lt;a href='test.com'&gt;Click to my site&lt;/a&gt;</description>

I don't want to be escaped, what should I do?

As far as I know, <![CDATA[MyInfo]]> tags need to be added to the HTML code in the xml, similar to the following.

<![CDATA[<a href='http://test.com'>Click to my site</a>]]>"

But I don't know how to do this in Django framework.

Back to Top