Quantcast
Channel: How to access data in get_context_data RSS Feed django 2.2 - Stack Overflow
Viewing all articles
Browse latest Browse all 2

How to access data in get_context_data RSS Feed django 2.2

$
0
0

I'm trying to access the context dictionary that is returned by a modified 'get_context_data' function in the LatestVideosFeed so I can use it in a 'news feed' I'm trying to make because the context that is returned contains the author of the video.I've been following these docs https://docs.djangoproject.com/en/2.2/ref/contrib/syndication/ and I can't figure out how to access the context dictionary that returns from the get_context_data(self, item, **kwargs): It works and when I do a debug print just before the return it returns a dictionary with the last entry as the user that uploaded the video. the debug print is print(context['author']) which returns as expected everytime the feed is interacted with.

feeds.py

class LatestVideosFeed(Feed):    link = '/video-feeds/'    description = 'New Video Posts'    def items(self):        return VideoPost.objects.all()    def get_context_data(self, item, **kwargs):        context = super().get_context_data(**kwargs)        context['author'] = item.author        print(context['author'])        return context    def item_title(self, item):        return item.title    def item_description(self, item):        return item.description    def item_link(self, item):        return reverse('video_post', args=[item.pk])

views.py

def video_list(request):    feeds = feedparser.parse('http://localhost:8000/profs/video-feeds')    return render(request, 'vids/video_list.html', {'feeds': feeds})

template

{% for thing in feeds.entries %}<h1>Author</h1><br>        {{thing.author}} <-- Nothing is printed here<h1>Title</h1>        {{thing.title}}<br><h1>Description</h1>        {{thing.summary}}<br><h1>Video Link</h1><a href="{{thing.link}}">{{thing.title}}</a><br>{% endfor %}

Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images