RSS (Really Simple Syndication) is a way to share frequently updated content like blog posts, news articles, or podcasts in a standardized XML format. Django provides built-in support for generating RSS feeds using the django.contrib.syndication
framework.
In this guide, you’ll learn how to:
-
Understand the basics of RSS in Django
-
Create and configure a feed
-
Link it to your models (e.g., blog posts)
-
Publish and test the feed
-
Follow best practices and avoid common issues
Prerequisites
Ensure the following:
-
You have a Django project running
-
You have an app (e.g.,
blog
) with a model likePost
Step 1: Enable the Syndication Framework
Make sure django.contrib.syndication
is added in your INSTALLED_APPS
in settings.py
.
INSTALLED_APPS = [
...
'django.contrib.syndication',
]
No migrations or extra installation are required.
Step 2: Define a Feed
You’ll create a class-based feed using Django’s Feed
class.
Example: Blog Feed for Latest Posts
Create a file feeds.py
in your app directory:
# blog/feeds.py
from django.contrib.syndication.views import Feed
from django.urls import reverse
from .models import Post
class LatestPostsFeed(Feed):
title = "My Blog"
link = "/rss/"
description = "Latest posts from my blog."
def items(self):
return Post.objects.order_by('-created_at')[:5]
def item_title(self, item):
return item.title
def item_description(self, item):
return item.body[:200] # Short snippet
def item_link(self, item):
return reverse('post_detail', args=[item.pk])
Step 3: Wire Up the Feed to URLs
Add the feed to your urls.py
.
blog/urls.py
or main urls.py
from django.urls import path
from .feeds import LatestPostsFeed
urlpatterns = [
path('rss/', LatestPostsFeed(), name='post_feed'),
]
Now visiting http://127.0.0.1:8000/rss/
will serve your RSS feed.
Example Output
When you visit /rss/
, Django returns an RSS XML document:
<rss version="2.0">
<channel>
<title>My Blog</title>
<link>/rss/</link>
<description>Latest posts from my blog.</description>
<item>
<title>Welcome to My Blog</title>
<link>/post/1/</link>
<description>This is the first post on my blog...</description>
<pubDate>Mon, 20 May 2025 18:00:00 GMT</pubDate>
</item>
...
</channel>
</rss>
You can view this in any RSS reader or browser with XML support.
Optional Enhancements
1. Add item_pubdate
def item_pubdate(self, item):
return item.created_at
2. Include Author
def item_author_name(self, item):
return item.author.username
3. Custom Feed Titles
If you're filtering feeds by category or user, you can override get_object
:
def get_object(self, request, category_slug):
return get_object_or_404(Category, slug=category_slug)
def items(self, obj):
return Post.objects.filter(category=obj)
And update urls.py
:
path('rss/category/<slug:category_slug>/', CategoryFeed(), name='category_feed'),
Best Practices
Tip | Explanation |
---|---|
✅ Limit items | Don’t overload the feed—5–10 items is good |
✅ Use absolute URLs | If using external readers, ensure links are full URLs |
✅ Provide meaningful descriptions | Summaries should entice users to click |
✅ Set pubDate | Improves sorting and display in feed readers |
✅ Use ETag and caching |
Improves performance for repeated requests |
❌ Common Pitfalls
Problem | Cause | Fix |
---|---|---|
RSS not showing | Missing Feed class or URL pattern |
Check imports and route |
Wrong link in <item> |
item_link returns a relative URL |
Use request.build_absolute_uri() if needed |
500 error | Missing or invalid data in item_ methods |
Ensure fallbacks and valid data for all items |
Final Project Structure
blog/
├── feeds.py # Feed classes
├── models.py # Post model
├── urls.py # Include feed URL
├── views.py
├── templates/
✅ Summary
Django's RSS support makes it easy to share content with users and applications in a standardized way.
You’ve learned how to:
-
Create an RSS feed using Django’s syndication framework
-
Customize the feed with titles, descriptions, and links
-
Integrate it with your Django project
-
Enhance it with pubDates and filtering
Want More?
Let me know if you’d like to extend this with:
-
Atom feed support
-
RSS feed for comments
-
Email or webhook integration