1👍
✅
import the json module
import json
Then Try this in your request method
data = json.dumps([{"square": 0, "key": 0}, {"square": 1, "key": 1}, {"square": 4, "key": 2}])
return HttpResponse(data, content_type="application/json")
NOTE
Using single quotes as in your snippet would result in the following output
'["{\\"square\\": 0, \\"key\\": 0}", "{\\"square\\": 1, \\"key\\": 1}", "{\\"square\\": 4, \\"key\\": 2}"]'
Its confusing for a seeker , hence i used the above method. But it depends on choice.
0👍
def get_ecommdata(request):
print "inside get_ecommdata"
list_square = [
{"square": 0, "key": 0},
{"square": 1, "key": 1},
{"square": 4, "key": 2}
]
data = json.dumps(list_square)
return HttpResponse(data, content_type='application/json')
- 'unicode' object has no attribute 'has_header'
- How to call a superclass method and return the subclass implementation?
- Creating a variable field in model Django
- How to loop over a queryset for instantiate all formset?
- Issue using Messages in Django Template
Source:stackexchange.com