A simple Django Application to pull RSS Feeds, pars them and deliver them via JSON

views.py 613B

123456789101112131415161718192021
  1. # -*- coding: utf-8 -*-
  2. from __future__ import unicode_literals
  3. from django.shortcuts import render, HttpResponse
  4. from django.template.loader import render_to_string
  5. from django.http import JsonResponse
  6. from .models import FeedItem
  7. import json
  8. from prettyprint import pp
  9. def NewsItemsJson(request):
  10. headlines = FeedItem.objects.all().order_by('-published')[:6]
  11. output = []
  12. i = 0
  13. for line in headlines:
  14. html = render_to_string('dash/news_slider_item.tpl.html', {'item': line, 'key': i}, request, )
  15. output.append(html)
  16. i += 1
  17. return JsonResponse(output, safe=False)