RSS/Atom Feeds with Syndication Framework
A snippet showing how to create RSS/Atom feeds.
# models.py
from django.db import models
class News(models.Model):
title = models.CharField(max_length=120)
slug = models.SlugField(unique=True)
created_at = models.DateTimeField(auto_now_add=True)
# admin.py
from django.contrib import admin
from .models import News
@admin.register(News)
class NewsAdmin(admin.ModelAdmin):
list_display = ("title","created_at")
# feeds.py
from django.contrib.syndication.views import Feed
from .models import News
class LatestNewsFeed(Feed):
title = "Latest News"
link = "/news/"
description = "Updates on the latest news."
def items(self): return News.objects.order_by("-created_at")[:20]
def item_link(self, item): return f"/news/{item.slug}/"
# urls.py
from .feeds import LatestNewsFeed
path("feeds/latest/", LatestNewsFeed(), name="news-feed")
Explanation:
-
Use
django.contrib.syndicationfeeds to publish RSS/Atom easily. -
Implement
items()and link methods for entries.
- Category Utilities & Miscellaneous
- Total Views 271
- Last Modified 17 July, 2026
- Tags #rss #atom #feeds #utilities
Previous snippet
Simple Sitemap with django.contrib.sitemaps
Next snippet