Answer the question
In order to leave comments, you need to log in
How to add the ability to host third-party feeds to a rss feed created in django?
Created an RSS feed in django. News is added through the admin panel and immediately automatically generated in the xml file.
feeds.py
from django.contrib.syndication.views import Feed
from django.template.defaultfilters import truncatewords
from .models import Posts
from django.urls import reverse
class LatestPostsFeed(Feed):
title = 'Новости связанные с недвижимостью и не только'
link = ''
description = 'Новые публикации связанные с недвижимостью и не только'
def items(self):
return Posts.objects.order_by('-created_at')
def item_title(self, item):
return item.title
def item_description(self, item):
return truncatewords(item.content, 30)
def item_link(self, item):
return reverse('detail_post', args={item.pk})
from django.urls import path
from .views import *
from .feeds import LatestPostsFeed
urlpatterns = [
path('', BlogPage.as_view(), name='blog'),
path('/<int:pk>/', BlogDetail.as_view(), name='detail_post'),
path('/RSSfeed/', LatestPostsFeed(), name='post_feed'),
]
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question