Vaibhav Mishra
Vaibhav Mishra

Reputation: 103

How to extract Data from Django Queryset

How to retrieve the data from Django queryset for use in a variable

When an output is received in below form after running the query

<QuerySet [{'name': 'John'}]>

I want to use the value 'John' in a variable for further processing.

How do I extract this ?

Upvotes: 5

Views: 13046

Answers (2)

biswa1991
biswa1991

Reputation: 546

k = <QuerySet [{'name': 'John'}]>
k[0] = {'name': 'John'}

Queryset is a list.

Upvotes: 3

Sandy
Sandy

Reputation: 46

Try with values_list().

myValues = myQuerySet.values_list()

Upvotes: 1

Related Questions