python - Retrieving JSON from HttpResponse from Django view -


so in view 1 of django apps, method returns httpresponse object.

json_str = json.dumps(json_dict) return httpresponse(json_str, content_type="application/json") 

in test module app (tests.py), have simulated request

def setup(self):     c = client()     response = c.get('/url/to/view/') 

from read in django testing documentation, response response object, similar not same httpresponse object. how retrieve json string response?

you can retrieve response json this:

import json  response = json.loads(c.get('/url/to/view/').content) 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -