RSS (Really Simple Syndication) Feed

RSS (Really Simple Syndication) is a web feed that allows users and applications to access updates to websites in a standardized, computer-readable format. These feeds can, for example, allow a user to keep track of many different websites in a single news aggregator. Django comes with an library to create atom feed for our blog. 

Creating views for RSS Feed – 

Go to blog app directory and create a file feeds.py and paste the below code.

Python3




from django.contrib.syndication.views import Feed
from django.template.defaultfilters import truncatewords
from .models import posts
from django.urls import reverse
from django.utils.feedgenerator import Atom1Feed
 
class blogFeed(Feed):
    title = "w3wiki"
    link = "/posts/"
    description = "RSS feed of w3wiki"
 
    def items(self):
        return posts.objects.filter(status = 1)
 
    def item_title(self, item):
        return item.title
       
    def item_description(self, item):
        return item.metades
 
    def item_link(self, item):
       return reverse('post_detail', args =[item.slug])
 
class atomFeed(Feed):
    feed_type = Atom1Feed


Create Routes for RSS Feed – 

To route the RSS feed go to urls.py file of the app you are using for generating feed and add the route

Python3




# importing django routing libraries
from . import views
from django.urls import path, include
from .views import * from .feeds import blogFeed
 
urlpatterns = [
.....
    # RSS route 
    path("posts / feed", blogFeed(), name ="feed"),
.....
]


Sample Feed

Sample Feed

How to add RSS Feed and Sitemap to Django project?

This article is in continuation of Blog CMS Project in Django. Check this out here – Building Blog CMS (Content Management System) with Django

Similar Reads

RSS (Really Simple Syndication) Feed

RSS (Really Simple Syndication) is a web feed that allows users and applications to access updates to websites in a standardized, computer-readable format. These feeds can, for example, allow a user to keep track of many different websites in a single news aggregator. Django comes with an library to create atom feed for our blog....

Sitemap –

...

Contact Us