1

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?

doniyor
  • 36,596
  • 57
  • 175
  • 260

2 Answers2

3

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]
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • it says: Variables and attributes may not begin with underscores. fieldname in my model starts with _fieldname. is that bad? – doniyor Aug 16 '13 at 20:57
  • See http://stackoverflow.com/questions/13693888/accessing-dict-elements-with-leading-underscores-in-django-templates. It'll help in your case. – alecxe Aug 16 '13 at 20:58
1

{{ object.column }} is the template syntax.

Peter DeGlopper
  • 36,326
  • 7
  • 90
  • 83