0

I was able to create a select list using bootstrap for my 'sell.html': enter image description here

<div class="form-group">
    <select class="form-control","input-group" id="sel1" autocomplete="off" autofocus name="symbol"  type="text"/>
    <option disabled="" selected="" value="">Symbol</option>
    {% for i in symbol %}
    <option value="{{ i.Symbol }}">{{ i.Symbol }}</option>
    {% endfor %}
   </select>
</div>

The problem is am not able to pass it to @app.route of sell...

# else if user reached route via GET (as by clicking a link or via redirect)
        b_symbol=db.execute("SELECT Symbol FROM portfolio")
        return render_template("sell.html",symbol=b_symbol)


@app.route("/sell", methods=["GET", "POST"])
@login_required
def sell():
    """Sell shares of stock."""
.
.
.
.
#ensure user symbol was submitted
if not request.args.get('symbol'):
     return apology("Enter symbol")

even when i use:

if not request.args.getlist('symbol'):
         return apology("Enter symbol")

i get the same result in either cases..."Enter symbol" Please help me find my mistake.Thank you

0

1 Answer 1

0

After going through the code over and over ...i made a few changes and it worked perfectly..

1) as select list is in the "forms" in bootstrap i had changed this..

if not request.args.getlist('symbol'):
         return apology("Enter symbol")

to

if not request.form.get('symbol'):
         return apology("Enter symbol")

2) the mistake was in my flask code too .... there i had set the var for the table user_shares(gets the shares from the portfolio table) to directly compare with the int type shares i had received after user input.. so before..

user_shares = db.execute("SELECT Shares FROM portfolio WHERE id = :id AND    symbol=:symbol", id=session["user_id"], symbol=symbol)

shares=int(request.form.get("shares"))
if user_shares < shares:
     return apology("Not enough Shares")

after correction

user_shares = db.execute("SELECT Shares FROM portfolio WHERE id = :id AND symbol=:symbol", id=session["user_id"], symbol=symbol)
user_shares=user_shares[0]['Shares']
shares=int(request.form.get("shares"))
if user_shares < shares:
    return apology("Not enough Shares")

You must log in to answer this question.

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