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
Post a Comment