Reputation: 1810
Disclaimer: I am new to django but have coded in Drupal
I need to return JSON data to my webpage. In my code,
x = serializers.serialize('json', Temp.objects.all())
returns
[{"pk": 1, "model": "wizard.temp", "fields": {"p": "message", "k": null, "m": null, "v": "PLEASE WAIT -- Counting and enumerating your images..."}}]'
How do I remove the leading and trailing brackets -- that is, the [ and ] ?
It seems only Firefox understands data[0]['pk'], so I'd like to instead do data['pk'].
Upvotes: 0
Views: 845
Reputation: 154464
You want to be serializing only one instance of Temp
. For example, to serialize only the first instance:
serializers.serialize('json', Temp.objects.all()[0])
Upvotes: 1