I can't print a queryset value.

41 views
Skip to first unread message

karlna...@gmail.com

unread,
Jan 3, 2018, 2:20:29 AM1/3/18
to Django users
I am trying to pass a queryset value as an argument to a method but it won't proceed; it shows no error. And I tried printing it like this:
for id in Review.objects.values_list('id', flat=True):
print("ID: " + id)
Output:
1

However, it worked and looped when I changed it to this:
for id in Review.objects.values_list('id', flat=True):
print(id)
Output:
1
2
3
4
5


My other problem is when using a queryset value in my method:

This works:
insert_to_db(id)

But this does not:
insert_to_db(id, result)


Any help would be greatly appreciated :)

James Schneider

unread,
Jan 3, 2018, 2:32:51 AM1/3/18
to django...@googlegroups.com



My other problem is when using a queryset value in my method:

This works:
insert_to_db(id)

But this does not:
insert_to_db(id, result)


Any help would be greatly appreciated :)

What is the insert_to_db function? That's probably where your issue is. Without that code, there probably isn't much that anyone can tell you.

-James

13515...@qq.com

unread,
Jan 3, 2018, 5:14:46 AM1/3/18
to django-users
This will work:
>>> for id in Review.objects.values_list('id',flat=True):
...   print('ID:%d' % id)
...
ID:1
ID:2
ID:3
ID:4
ID:5
ID:6

and i don't know what you say in ur problem2

wblueboat
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/8003bf92-c580-4d10-9e42-d4fade579bd9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages