When I enter amount, name, expinc in my html form it works for the first time, i.e. the entered data goes into database tables for the first time but whenever I try to enter data again it doesn't show up in tables. It looks like db.execute function executing not more than one time.

@app.route("/buy", methods=["GET", "POST"])
def buy():
    if request.method == "GET":
        return render_template("buy.html")
        amounts = int(request.form["amount"])
        names = request.form["name"]
        expincs = request.form["expinc"]

        db.execute("INSERT INTO histories (id, amount, name, expinc) \
                    VALUES(:id, :amount, :name, :expinc)", \
                    id=session["user_id"], amount=usd(amounts),\
                    name=names, expinc=expincs)

        db.execute("INSERT INTO portfolio (id, amount, name, expinc) \
                    VALUES(:id, :amount, :name, :expinc)", \
                    id=session["user_id"], amount=usd(amounts), \
                    name=names, expinc=expincs)
        return redirect(url_for("index"))

1 Answer 1


There is nothing in the posted code that would prevent the db.execute from executing more than one time. One possible explanation is the primary key or a unique index on the tables is preventing duplicates. For example if id is the primary key on histories, it will only allow one row per user id.

You must log in to answer this question.

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