0

My index.html

{% extends "layout.html" %}

{% block title %}
    Portfolio
{% endblock %}

{% block main %}
<!-- Seen from HTML of finance.cs50.net-->
<!-- making an int for storing the value of share prices at current value-->
{% set sum  = 0|int %}
<table class="table table-striped">
        <thead>
            <tr>
                <th>Symbol</th>
                <th>Name</th>
                <th>Shares</th>
                <th>Price</th>
                <th>TOTAL</th>
            </tr>
        </thead>
        <tbody>

            <!-- for loop iterating over the stocks-->
            {% for stock in stocks %}
                <!-- obtaining value of stock from lookup function -->
                {% set i = stock['symbol']|lookup %}

                <tr>
                    <td>{{ i['symbol'] }}</td>
                    <td>{{ i['name'] }}</td>
                    <td>{{ stock['shares'] }}</td>
                    <td>{{ i['price'] }}</td>
                    <td>{{ i['price']*stock['shares'] }}</td>
                    <!-- making a variable and typecasting it to int-->
                    {% set j =  i['price']*stock['shares']|int%}
                    <!-- storing it in sum-->
                    {% set sum = sum + j %}

                </tr>
            {%endfor%}


            <tr>
                <td colspan="4">CASH</td>
                <!--cash amount-->
                <td>{{cash_amt[0]['cash']}}</td>

            </tr>
        </tbody>
        <tfoot>
            <tr>
                <td colspan="4"></td>
                <!-- add sum and cash-->
                <td>{{sum + cash_amt[0]['cash']}}</td>
            </tr>
        </tfoot>
    </table>

{% endblock %}

Please help Image of result

How to solve the total problem :(

1

I tried the same. Then I found this one: http://jinja.pocoo.org/docs/2.9/templates/#assignments (basically: won't work)

I chose to calculate the total value in Python instead, and pass it in another variable.

1
  • Thanks for the quick reply :)
    – Crazy8
    Sep 23 '17 at 2:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .