G
G
Geo5552020-02-06 15:34:34
Django
Geo555, 2020-02-06 15:34:34

How do I get the number 1554 instead of {'age__sum': 1554} when creating my own template tag?

Has own tag

spoiler
@register.simple_tag
def total_age():
    people = Person.objects.all()
    age = people.aggregate(Sum("age"))
    return age

In the html page, the code is: Всего = {% total_age %}
In the browser: Total = {'age__sum': 1554
} in browser: Total = 1554

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem, 2020-02-06
@Geo555

return age.get('age__sum', 0)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question