Skip to main content
Asking about point 3. now, absolutely stuck. Brick walled.
Source Link
nvs0000
  • 179
  • 1
  • 9

Pset7, Index: For loop not workingHow to use loops in Python and Jinja?

I canfelt like I could understand the for loops great in c, but seem to be hitting a wall here. Some generic conceptual questions before i get into it:

  1. ANSWERED. what sequence does the program run, does it read HTML first or the Python scripts first?

  2. ANSWERED. what is the difference between the for loop in HTML and for loop in python?

  3. Main/In depth question: I can't seem to to get my "Position" dict to loop. My sharesOwned are looping great, but not the dict(position) i created. Can someone tell me why please?

NEED HELP:

  1. Main/In depth question: I can't seem to to get my sharesNow=lookup(share['symbol']) to loop. My sharesOwned in HTML are looping great, but not any thing else.

Pset7, Index: For loop not working

I can understand the for loops great in c, but seem to be hitting a wall here. Some generic conceptual questions before i get into it:

  1. what sequence does the program run, does it read HTML first or the Python scripts first?

  2. what is the difference between the for loop in HTML and for loop in python?

  3. Main/In depth question: I can't seem to to get my "Position" dict to loop. My sharesOwned are looping great, but not the dict(position) i created. Can someone tell me why please?

Pset7, Index: How to use loops in Python and Jinja?

I felt like I could understand the for loops great in c, but seem to be hitting a wall here. Some generic conceptual questions before i get into it:

  1. ANSWERED. what sequence does the program run, does it read HTML first or the Python scripts first?

  2. ANSWERED. what is the difference between the for loop in HTML and for loop in python?

NEED HELP:

  1. Main/In depth question: I can't seem to to get my sharesNow=lookup(share['symbol']) to loop. My sharesOwned in HTML are looping great, but not any thing else.
Source Link
nvs0000
  • 179
  • 1
  • 9

Pset7, Index: For loop not working

I can understand the for loops great in c, but seem to be hitting a wall here. Some generic conceptual questions before i get into it:

  1. what sequence does the program run, does it read HTML first or the Python scripts first?

  2. what is the difference between the for loop in HTML and for loop in python?

  3. Main/In depth question: I can't seem to to get my "Position" dict to loop. My sharesOwned are looping great, but not the dict(position) i created. Can someone tell me why please?

Index in python/flask:

@app.route("/")
@login_required
def index():

    #get and consolidate user data in database 
    sharesOwned = db.execute("SELECT symbol, price, name, SUM(shares) AS quanties FROM shares WHERE id=:id GROUP by symbol, symbol ORDER by symbol", id=session["user_id"])
    
    #loop through "position" dict
    for share in sharesOwned:
        sharesNow=lookup(share['symbol'])
        
        position={
            'name':sharesNow["name"],
            'pricey': sharesNow['price'],
            'symbol':sharesNow["symbol"]
            }

    rows=db.execute("SELECT * FROM users where id = :id", id = session["user_id"])
    return render_template("index.html", sharesOwned=sharesOwned, position=position, name=rows[0]["username"])

index.html:

{% extends "layout.html" %}

{% block title %}
    Index
{% endblock %}

{% block main %}

    <h2>RESULTS:</h2>

    <ul>
        <li><h2> {{ name }}</h2></li>
    </ul>
    
<table class="table table-striped">

        <thead>
            <th>Share Symbol</th>
            <th>Shares Name</th>
            <th>Number of Shares</th>
            <th>Current price</th>
            <th>Total value</th>
        </thead>
        
         {% for share in sharesOwned %}
            <tr>
                <td>{{ share.symbol }}</td>
                <td>{{ position.name }}</td>
                <td>{{ share.quanties }}</td>
                <td>{{ position.pricey }}</td>
            </tr>
        {% endfor %}
        

        


    </table>
{% endblock %}

Result: enter image description here