Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jinja template to calculate the average

I'm trying to display the average of numbers using jinja template but I couldn't make it up.

I'm getting the value of 'points' column from the Google app engine datastore entity 'Score'

Using python code and taking it in jinja template and I wanted to calculate the average of points and display through this template.

{% for num in number%}
        {{num.points}}
{% endfor %}
like image 635
Anna Avatar asked Oct 31 '25 10:10

Anna


1 Answers

{% set score = [] %}
{% for num in number %}
    {% if score.append(num) %}{% endif %}
{% endfor %}
Average score: 
{{ score | sum / score | count }}

http://jinja.pocoo.org/docs/dev/templates/

like image 102
LeonF Avatar answered Nov 03 '25 02:11

LeonF