Hot answers tagged

4

Since "stocks" are in one list and "currentprices" are in another list you will get this result when you use two lists and two loops. One solution would be to use one loop and use currentprices[i] where i is indexed to the row in the "stocks" list. Another option would be to add a "price" key to each "stocks" row in the index() function instead of building ...


4

Inside the function for the respective routes you can just call the function "flash(message)" before the "return redirect()" function, where "message" is the message you want to display. for example: flash ("Bought") return redirect(url_for("index"))


3

The for loop is working and is displaying exactly the data it has. And it technically (theoretically?) is identical to a for loop in C. Perform this code x times. Syntactically, you (normally) tell C how many times (eg for (i = 0; i < strlen(somestring); i++). The for stock in stocks notation is "syntactic sugar"; it knows how long stocks is, so it does ...


2

How about if you create a new session key, like session['action'] = 'Bought' that gets set in the appropriate route?


2

Instead of working with two arrays (portfolio and quote), consider adding a key/value pair to the portfolio array for the value of the holding. In index, where you iterate over portfolio you could try something like: lookup the stock, then add a key to line with the extended price: line["value"] = price (from lookup) * shares (from line). Everything you need ...


1

Have you validated your html? Does it complain about the <dt>...</dt> tags? From MDN: The HTML <dt> element (or HTML Description Term Element) identifies a term in a description list. This element can occur only as a child element of a <dl>. Since you are building table rows, it probably is just a typo.


1

I would like to put the data from the data list in a separate file and then get it back to python and then send it to the Html table with the existing jinja syntax and not change anything in the render template function. The data in the data list looks like csv format. If it was stored in a file, retrieving the data would become a task similar to pset6 DNA: ...


1

It's running but nothing "matches" (ie is true) because of the date formats. Assuming "due_date" is TEXT in the db with the format "YYYY-MM-DD", current_date needs to be in the same format. That can be accomplished by changing this current_date=timestamp.date() to this current_date=str(timestamp.date()). That will coerce the ...


1

You need to pass SHEET to the template in your render_template call.


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

{% block main %} {% if empty == "False" %} // TODO Somethig <p>NOOO</p> {% endif %} {% endblock %} Easy fix I was trying to to pass a variable empty as a parameter with value to index.html, where it was checked {% if {{ empty }} == "False" %}` The idea is good, but it did not work. Apparently instead of {% if {{ ...


1

I was tripped out by a similar problem for quite some time before I actually figured out something that worked for me. In my case, what I did is I declared an empty list of rows and initialized an index variable to 0. Then I assigned my SELECT statement to another variable (ex.: data). Then in the for loop in application.py I constructed each row by ...


1

@dinocodersaurus's link :) flash ("Bought") return redirect(url_for("index"))


1

the share in for share in sharesOwnedis the object itself so when u try to use something like priceNow[share] , it doesnt make sense. if you have a diff pricenow list then u can iterate both list using a function called zip(). It works something like this: {% for share, price in share_price %} <tr>enter code here <td>{{ share....


1

This sql "SELECT symbol, price, name, SUM(shares) AS quanties FROM shares WHERE id=:id" always returns one row. Try it in sqlite3/phpliteadmin. You need a GROUP BY clause . Since you (presumably) want one row per symbol, you would add GROUP BY symbol after the where clause (try that in sqlite3/phpliteadmin to see the difference).


1

This is part of the broader change from PHP to Python, which you allude to. The simple explanation for that change on CS50's Medium blog was "It’s time." Switching to Python enabled CS50 to use the microframework Flask for pset6 and pset7. Flask uses Jinja syntax in its templates, which you can read more about here. However, it is inaccurate to call this ...


1

There is no stocks array being sent return render_template("index.html", cash=str(round(cash[0]["cash"], 2)), total_worth=total_asset). Therefore, stocks is an empty array in the html. Therefore {% for stock in stocks %} executes 0 times.


1

Try using the dot operator instead. {{stock.stock}} and{{stock.total_shares}}


1

holdings in your python script is a dict. The {% for holding in holdings %} in the jinja template suggests a list of dicts instead. {% holding.total + holding.cash %} is the part crashing your script. Use {{ }} instead of {% %} for those.


Only top voted, non community-wiki answers of a minimum length are eligible