Creating feeds for your blog posts

Django has a built-in syndication feed framework that you can use to dynamically generate RSS or Atom feeds in a similar manner to creating sitemaps using the site's framework. A web feed is a data format (usually XML) that provides users with frequently updated content. Users will be able to subscribe to your feed using a feed aggregator, a software that is used to read feeds and get new content notifications.

Create a new file in your blog application directory and name it feeds.py. Add the following lines to it:

from django.contrib.syndication.views import Feedfrom django.template.defaultfilters import truncatewordsfrom .models import Postclass LatestPostsFeed(Feed):    title = 'My blog' link = '/blog/' ...

Get Django 2 by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.