Sergey
Sergey

Reputation: 167

how to get the property from an object?

please help bring in the template property of the object.

usually for a set of objects I deduce properties of the loop through the "FOR":

{% for entrie in news_all %}
    <br /><strong>{{ entrie.title }}</strong>
{% endfor %}

but now I passed to the template is only one object, so no need to use a loop

Upvotes: 0

Views: 33

Answers (1)

alecxe
alecxe

Reputation: 473833

Just get the object field using dot notation: {{ entrie.title }}

(assuming entrie is passed in the template context).

Though, if you are passing a queryset in the context, the result of objects.filter(), for example, that contains only one object, you can still use the dot notation: first get the first element from a queryset, then an attribute/field:

{{ entries.0.title }}

See some examples here.

Hope that helps.

Upvotes: 2

Related Questions