json - How can i return single object from Django view to Jquery -


if use this

data = serializers.serialize('json', book.objects.all()) return httpresponse(data, mimetype='application/javascript') # redirect after post 

then json objects

but if need return single object

then error

data = serializers.serialize('json', singleobject) return httpresponse(data, mimetype='application/javascript') # redirect after post 

the error says

object not iterable 

read docs on serialization

the arguments serialize function format serialize data (see serialization formats) , queryset serialize. (actually, second argument can iterator yields django objects, it'll queryset).

and try this:

data = serializers.serialize('json', [singleobject]) 

also, this thread answers question.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -