Weekly letter pythonprogramming.email
Hi,
To get the curated list of awesome python articles from all over the Internet, please subscribe with pythonprogramming.email. This is specifically suitable for beginners.
Advertise with us
seo django feeds   0   2133
How to generate ATOM/RSS feed for Django website


In previous articles, we learned how to create a sitemap for the Django website. A valid sitemap increases your website's search engine ranking. Hence good for search engine optimization. 

Similarly, adding a robot.txt file is good for your website. It tells crawlers, which page to crawl and which page not to crawl for indexing.

In this article, we will see how to generate RSS feed on your Django website. 

The RSS feed help to keep up readers with their favorite blogs, news sites, and other websites. RSS allows the content and new updates to come to the reader. Generally, you use RSS to syndicate or subscribe to the feed of a website, blog or almost any media content that is updated online


Create a file in your app directory, parallel to urls.py file and name it feeds.py. Paste the below code in it. 

In the below sample example, we are fetching posts/articles from the database of pythoncircle.com. We have implemented four methods, item, item_title, item_description and item_link. The code has been updated with comments.


class LatestEntriesFeed(Feed):
title = "PythonCircle.com: New article for Python programmers every week"
link = "/feed/"
description = "Updates on changes and additions to python articles on pythoncircle.com."
# return 10 recently created/updated posts
def items(self):
return get_recent_updated_posts(number_of_posts=10)

def item_title(self, item):
return item.title
# return a short description of article
def item_description(self, item):
return item.description
# create and return the article URL
def item_link(self, item):
return reverse('appname:index', args=(item.post_id,))



Now in your project's urls.py file (not in any app's urls.py file) add below code.

from appname.feeds import LatestEntriesFeed()

# add feeds path
urlpatterns += [
path(r'feed/', LatestEntriesFeed()),
]


Restart/Reload your Django app and go to pythoncircle.com/feed/ or localhost:8000/feed/.

You can validate if RSS feed generated is valid or not.


seo django feeds   0   2133

Related Articles:
How to reset Django superuser password
This article explains 3 methods to reset the user password in Django, What command should be used to reset the superuser password from the terminal in Django application, Changing the user password in Django...
Encryption-Decryption in Python Django
How to encrypt and decrypt the content in Django, Encrypting the critical information in Django App, Encrypting username, email and password in Django, Django security...
How to upload an Image file in Django
This article explains the simple steps of uploading and storing an image in Django application, After storing the image, how to use it in Django template or emails, Uploading a file in Django, Storing image in Django model, Uploading and storing the image in Django model, HTML for multipart file upload...
Getting query params from request in Django
In this article, we will see how to access the query parameters from a request in the Django view, Accessing GET attribute of request, get() vs getlist() method of request in Django, query parameters Django,...
SUBSCRIBE
Please subscribe to get the latest articles in your mailbox.

© 2017-2020 Python Circle   Contact   Sponsor   Archive   Sitemap