by pindi · 13y ago · 0 comments
Am I missing something? What's wrong with:
return HttpResponse(json.dumps(data), mimetype='application/json')
Wrap it up in a convenience function and you're done.The JSONResponse class suggested automatically implements JSONP, which is extremely dangerous. Consider a view on /accounts/info which returns some information about the currently logged in user. A malicious site could embed
<script src="http://example.com/accounts/info?callback=someFunction">
and access the account information of any user logged into your site. JSONP is a technique to bypass the same-origin policy in appropriate cases; don't just blindly apply it everywhere or you're giving up the protection of the policy.The way to deal with is __complex__ as a method on the object and recurse through asking the complex method to return nested simpler python types.
http://docs.python.org/2/library/functions.html#complex --and-- http://docs.python.org/2/library/cmath.html