'Article' object is not iterable ,why this error is popping up,while fetching data using primary no

44 views
Skip to first unread message

Ashutosh Mishra

unread,
Nov 4, 2020, 1:03:18 AM11/4/20
to Django REST framework
whenever i try to fetch data usinng primary key,getting above error
models.py
Screenshot from 2020-11-04 11-31-06.png

serializer.py
Screenshot from 2020-11-04 11-31-13.png

view.py
Screenshot from 2020-11-04 11-31-19.png

Xavier Ordoquy

unread,
Nov 4, 2020, 1:26:21 AM11/4/20
to django-res...@googlegroups.com
Hi,

Please, paste your code in the mail instead of screenshots, it makes it hard to read.
In your view, you are passing an Article instance to your serializer along with the many=True keyword which means the serializer will expect an iterable of Articles as the error suggests.

Regards,
Xavier O.
Linovia.


Le 4 nov. 2020 à 07:03, Ashutosh Mishra <ashutosh...@gmail.com> a écrit :

whenever i try to fetch data usinng primary key,getting above error
models.py
<Screenshot from 2020-11-04 11-31-06.png>

serializer.py
<Screenshot from 2020-11-04 11-31-13.png>

view.py
<Screenshot from 2020-11-04 11-31-19.png>


--
You received this message because you are subscribed to the Google Groups "Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-rest-fram...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-rest-framework/75f76a91-52ed-4cde-887c-26998ab2fe04n%40googlegroups.com.
<Screenshot from 2020-11-04 11-31-19.png><Screenshot from 2020-11-04 11-31-13.png><Screenshot from 2020-11-04 11-31-06.png>

Ashutosh Mishra

unread,
Nov 4, 2020, 1:28:26 AM11/4/20
to django-res...@googlegroups.com
So how can I resolve this?

You received this message because you are subscribed to a topic in the Google Groups "Django REST framework" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-rest-framework/2M7lfY2wlZc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-rest-fram...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-rest-framework/4A8683CF-1ACA-4A39-87FC-8254C35C98ED%40linovia.com.

Xavier Ordoquy

unread,
Nov 4, 2020, 1:31:01 AM11/4/20
to django-res...@googlegroups.com
The question is, what are you trying to do and what outcome are you expecting ?

Ashutosh Mishra

unread,
Nov 4, 2020, 1:32:37 AM11/4/20
to django-res...@googlegroups.com
I want to fetch a particular entry by using primary key,suppose if I put 1 the entry associated with 1 will appear

Michael Goffioul

unread,
Nov 4, 2020, 6:59:58 AM11/4/20
to django-res...@googlegroups.com

You specify many=True in the serializer constructor; hence the serializer expects a list of objects. You provide a single object; hence you get an error about argument not being iterable.

Ashutosh Mishra

unread,
Nov 4, 2020, 7:28:24 AM11/4/20
to django-res...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages