0
    @app.route("/buy", methods=["GET", "POST"])
@login_required
def buy():
    """Buy shares of stock"""
    if request.method == "GET":
        return render_template("buy.html")
    else:
        if not request.form.get("symbol"):
            return apology("missing symbol", 400)
        if not request.form.get("shares"):
            return apology("missing shares", 400)
        symbol = request.form.get("symbol")
        shares = request.form.get("shares")
        lis = lookup(symbol)
        cost = lis["price"]
        price = cost * shares
        return render_template("test.html", price=price)

error

price = cost * shares
TypeError: can't multiply sequence by non-int of type 'float'
1

The "sequence" in the error message is shares, which is a string. From MDN doc on sending form data:

Whichever HTTP method you choose, the server receives a string that will be parsed in order to get the data as a list of key/value pairs.

The "values" are always strings.

2
  • So I need to typecast using int()? Aug 24 '20 at 12:10
  • Nvm got it. Thanks a lot! Aug 24 '20 at 12:22

You must log in to answer this question.

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