Getting a JSON request in a view (using Django)

I am trying to configure the view to receive JSON notification from the API. I am trying to figure out how to get JSON data, and currently I have this as a starting point to see that the request is correctly accepted:

def api_response(request): print request return HttpResponse('') 

I know that a JSON object exists, because in print request it shows:

 META:{'CONTENT_LENGTH': '178', [Fri Sep 09 16:42:27 2011] [error] 'CONTENT_TYPE': 'application/json', 

However, both POST and GET QueryDicts are empty. How do I set up a view to receive a JSON object so that I can handle it? Thanks.

+4
source share
1 answer

Here is how I did it:

 def api_response(request): try: data=json.loads(request.raw_post_data) label=data['label'] url=data['url'] print label, url except: print 'nope' return HttpResponse('') 
+8
source

All Articles