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