Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django print value of query set

simple problem (i think).
I have following query:

hostname = Host.objects.get(pk=(host_id))
env = Host.objects.filter(cfthostname=hostname).values('cftos')
print(env)

what i get from print is:

<QuerySet [{'cftos': 'unix'}]>

how to make it:

unix
like image 382
gipcu Avatar asked Sep 07 '25 09:09

gipcu


1 Answers

Try the following:

instance = Host.objects.filter(cfthostname=hostname).values('cftos')[0]
env = instance['cftos']

Also, if you're only getting one value, you can use flat like below to do this in one line:

env = Host.objects.filter(cfthostname=hostname).values_list('cftos', flat=True)[0]
like image 97
Winston Avatar answered Sep 10 '25 03:09

Winston