Computer Science, asked by tspr810, 1 month ago

I was doing CS50x Finance buy implementation and reached a point where I got this error continuously. If anyone could tell where I am wrong.
I have also attached the error which I get. Any help would be appreciated

Attachments:

Answers

Answered by am2533
0

Answer:

orm, I always get returned to the error page stating "Must Provide Username" and I am not sure how it is getting to that point instead of one of my two error conditions.

Here is my buy function so far:

@app.route("/buy", methods=["GET", "POST"])

@login_required

def buy():

"""Buy shares of stock"""

# requested_quote = stock

if request.method == "POST":

if not request.form.get("symbol"):

return apology("must provide symbol", 403)

if not request.form.get("amount") or request.form.get("amount") < 1:

return apology("Please enter amount 1 or greater", 403)

stock = request.form.get("symbol")

amount = request.form.get("amount")

requested_quote = lookup(request.form.get("quote"))

cash = db.execute("SELECT cash FROM users WHERE id = :id", session["user_id"])

if requested_quote == None:

return apology ("Invalid Symbol", 400)

if (requested_quote["price"] * amount) > cash:

return apology("Not enough funds", 400)

else:

db.execute("INSERT INTO purchases (id, symbol, amount, share_price) VALUES(?, ?, ?, ?)",

(session["user_id"], stock, amount, requested_quote["price"]))

else:

return render_template("buy.html"

Similar questions