Sunday, August 02, 2009

output json on django

I just finish a job in django, and I use it for some ajax part of the project. So I generate json for this. Below is a snippet sanitize from the code my job use...

import json
from simplejson as json
from django.http import HttpResponse
from django.contrib.auth.decorators import login_required
from django.shortcuts import render_to_response
def generate_json(request):
#it can be a dictionary too, anything supported by simplejson
#do something here, to fill in somelist
response['content-disposition'] = 'attachment; filename=properties.json'
return response

So there it is...

p.s I need a way to display source code properly on my blog, idea?

No comments:

Post a Comment