I want to make add cash button on my cs50 finance, I have made separate html file for this and made a separate route for this but when I run it, It takes me straight to apology without showing me html form at all.Here is my python code.
@app.route("/addcash", methods=["GET", "POST"])
@login_required
def addcash():
#For personal touch add cash to user
if request.method == "POST":
#Take amount to be added
numb = request.form.get("amount")
if numb is None or numb == '' or numb < 1:
return apology ("Please enter valid amount")
else:
#Take user cash
row = db.execute ("select cash from users where id = :ii" , ii = session["user_id"])
#Now add the amount to users data base.
db.execute("UPDATE users SET cash = :cash WHERE id = :ide",cash = row[0]["cash"] + numb, ide = session["user_id"])
return redirect(url_for("index"))
else:
#This programe is taking me straight here.
return apology("Invalid mathod")
And here is my html
{% extends "layout.html" %}
{% block title %}
Please enter the amount you want to add!
{% endblock %}
{% block main %}
<form action="{{ url_for('addcash') }}" method="post">
<fieldset>
<div class="form-group">
<input autocomplete="off" autofocus class="form-control" name="amount" placeholder="amount" type="text"/>
</div>
<div class="form-group">
<button class="btn btn-default" type="submit">Add</button>
</div>
</fieldset>
</form>
{% endblock %}