简体   繁体   中英

django - how to get value of key-value queryset from values()

I am stuck not knowing how to do this. i am using values() method to get specific column from db but i dont know how to get the value of that column in queryset, i am getting after values() something like this:

[columnname: value]

I want to get only the value. I think, in views.py i can get the value with object['column'] , but how do i get the value in template in django?

or what is the best way to do this?

Use dot notation in Django templates:

{{ object.column }}

Dots have a special meaning in template rendering. A dot in a variable name signifies a lookup. Specifically, when the template system encounters a dot in a variable name, it tries the following lookups, in this order:

  • Dictionary lookup. Example: foo["bar"]
  • Attribute lookup. Example: foo.bar
  • List-index lookup. Example: foo[bar]

{{object.column}}是模板语法。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM