簡體   English   中英

從 Output 中刪除 QuerySet 格式

[英]Remove QuerySet format from Output

如何從 output 中刪除查詢集?

我的查詢格式

     Xname= final.objects.filter(fshape=shapeofpill).values('fnmae')
     XDescr= final.objects.filter(fshape=shapeofpill).values("fdescr")
     return render(request, 'myapp/home.html', {'Xname':Xname, 'XDescr':XDescr})

Output:

<QuerySet [{'fnmae': 'Dexmethylphenidate'}]>
<QuerySet [{'fdescr': 'Dexmethylphenidate is used in the treatment of adh'}]>

我只想要值,例如。 在第一個查詢中,我只想要 Dexmethylphenidate 作為 Output

如果您只想要值(而不是名稱鍵),您可以使用平面values_list並將其包裝在list()

Xname = list(final.objects.filter(fshape=shapeofpill).values_list('fnmae', flat=True))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM