richie
richie copied to clipboard
Add a RSS Feed
Feature Request
Is your feature request related to a problem or unsupported use case? Please describe. We would like to create a RSS Feed to be notified when a new blogpost has been published.
Describe the solution you'd like
Django provides a class django.contrib.syndication.views.Feed to create easily a RSS/Atom Feed.
We could make a generic PageRSSFeed class which takes a Page model as argument then retrieve information needed (url, title, description). In this way, we could create RSS Feeds according to setting.
A simple example from documentation:
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])
from django.urls import path
from myproject.feeds import LatestEntriesFeed
urlpatterns = [
# ...
path('latest/feed/', LatestEntriesFeed()),
# ...
]
Discovery, Documentation, Adoption, Migration Strategy https://docs.djangoproject.com/en/3.2/ref/contrib/syndication#django.contrib.syndication.views.Feed
Do you want to work on it through a Pull Request? Yes