Hot answers tagged

4 votes
Accepted

cs50 finance / pset-7 confused on index() table

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] ...
4 votes
Accepted

Using jinja to render template based on previous url - pset7 finance

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: ...
3 votes
Accepted

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

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 ...
2 votes

Using jinja to render template based on previous url - pset7 finance

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

pset7 index.html Jinja

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 ...
2 votes
Accepted

Is there a way in jinja to display a block in a specific page?

jinja handles conditionals. One possible solution: Add a conditional in the <footer> block and send an indicator when the profile page is rendered. Sample html code: <footer> {% if ...
1 vote

Finance app - object is not subscriptable

There are several problems in the HTML. One such is the select element needs the name attribute to represent the name of the associated data point submitted to the server. Here is some helpful doc ...
1 vote

Is there a way in jinja to display a block in a specific page?

DinoCoderSaurus did give a good answer, but you can do like this as well. Add this to your layout.html. {% block footer %} <p>Footer Content</p> {% endblock %} And for any page you ...
  • 138
1 vote

Jinja problem in Index PSET7

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 ...
1 vote

Flask Filter Search/List in Python

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 ...
1 vote
Accepted

CS50 Final Project Jinja For Loop Not Running

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 ...
1 vote
Accepted

My jinja not working like it should pset6 survey

You need to pass SHEET to the template in your render_template call.
  • 18.5k
1 vote

Pset 7 total not working

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 ...
  • 20.8k
1 vote

How to disable a table (portfolio) in index.html?

{% 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 ...
1 vote
Accepted

How to iterate through different shares in jinja to create the table in index.html

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 ...
  • 40
1 vote
Accepted

Pset7: How to get "Bought!" Alert in /Index when re-directing from /Buy (I tried IF condition, but failed)

@dinocodersaurus's link :) flash ("Bought") return redirect(url_for("index"))
  • 179
1 vote
Accepted

Jinja - for loop

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 ...
1 vote
Accepted

Pset7, Index, why does it not show other stocks i own?

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 ...
1 vote
Accepted

Why did CS50, 2017 swap from HTML/CSS to Jinja for Pset7?

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 ...
  • 1,412
1 vote

CS50 Pset7: rows inside the for loop are not showing up in index.html

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 {% ...
1 vote
Accepted

CS50 Pset7: rows inside the for loop are not showing up in index.html

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

Jinja template exception: "jinja2.exceptions.TemplateSyntaxError"

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....
  • 20.8k

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