I have a single object I want to serialize:
from django.core import serializers
...
return HttpResponse(serializers.serialize("json", get_object_or_404(Animal, pk=1)), mimetype="application/json")
This throws a “Not Iterable” error, as it seems that it expects that the second parameter should be iterable. How can I serialize a single object to JSON?
You can always wrap the object you want into a list and take back only the first element. Your second argument can be:
and when you deserialize,