Syndication Feed for JSON

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
from django.utils.feedgenerator import SyndicationFeed
from django.core.serializers.json import DjangoJSONEncoder
import json


class JSONFeed(SyndicationFeed):
    mime_type = "application/json"

    def write(self, outfile, encoding):
        data={}
        data.update(self.feed)
        data['items'] = self.items
        json.dump(data, outfile, cls=DjangoJSONEncoder)
        # outfile is a HttpResponse
        if isinstance(outfile, HttpResponse):
            outfile['Access-Control-Allow-Origin'] = '*'


class MyJSONFeed(MyPlainFeed):
    feed_type = JSONFeed

More like this

  1. HTTP (basic) auth enabled (new-style) syndication framework feed class by hupf 2 years, 5 months ago
  2. Class Feeds DRY TemplateTag by gmandx 3 years ago
  3. Django JSONP Decorator by cominatchu 2 years, 7 months ago
  4. Generic view mixing that allows output to JSON, HTML, HTML SNIPPETS by danielsokolowski 1 year, 9 months ago
  5. iTunes Podcast RSS Feed by Kyle_Dickerson 2 years, 10 months ago

Comments

(Forgotten your password?)