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
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]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With