Friday, January 3, 2020

Abhijeet Pal: Creating Feeds with Django

Django ships with built-in syndication feed generating framework, which is used to generate dynamic Atom and RSS feeds. RSS is an abbreviation for Really Simple Syndication, it’s a way to have information delivered to you instead of you having to go find it. RSS is basically a structured XML document that includes full or summarized text along with other metadata such as published date, author name, etc. Creating RSS Feeds with Django In this article, we are going to generate feeds for a blog application following is the models.py file. class Post(models.Model): title = models.CharField(max_length=200, unique=True) slug = models.SlugField(max_length=200, unique=True) author = models.ForeignKey( User, on_delete=models.CASCADE, related_name="blog_posts" ) updated_on = models.DateTimeField(auto_now=True) content = models.TextField() created_on = models.DateTimeField(auto_now_add=True) status = models.IntegerField(choices=STATUS, default=0) class Meta: ordering = ["-created_on"] def __str__(self): return self.title def get_absolute_url(self): from django.urls import reverse return reverse("post_detail", kwargs={"slug": str(self.slug)}) Create a new file feeds.py inside the application directory. from django.contrib.syndication.views import Feed from django.template.defaultfilters import truncatewords from .models import Post from django.urls import reverse class LatestPostsFeed(Feed): title = "My blog" link = "" description = "New posts of my blog." …

The post Creating Feeds with Django appeared first on Django Central.



from Planet Python
via read more

No comments:

Post a Comment

TestDriven.io: Working with Static and Media Files in Django

This article looks at how to work with static and media files in a Django project, locally and in production. from Planet Python via read...