I am implementing addcash function to finance and I have one issue with checking if input value is an integer value, the problem is whenever I input non-integer value for testing purposes my page breaks with error. Here is my code:
@app.route("/addcash", methods=["GET", "POST"])
@login_required
def addcash():
"""Add cash."""
if request.method == "POST":
if request.form.get("addcash") == "":
return apology("invalid input")
addCash = int(request.form.get("addcash"))
if not addCash:
return apology("invalid input, please try again")
db.execute("UPDATE users SET cash=cash+:addCash WHERE id = :user_id", user_id=session['user_id'], addCash=addCash)
return redirect(url_for("index"))
else:
return render_template("addcash.html")
The page gives me following error:
I also realized that my buy and sell functions also have this bug whenever inputing non-int value for testing purposes, how to fix this problem and return apology instead?