So, as the title says I can't figure out what I'm doing wrong to give the user a drop-down menu which contains the symbols of his/her stocks.
Thank you for your time in advance!
My intention is: -query database for his/her stocks -store it in a dict object as key->value pairs -pass it to sell.html via flask
Here is my sell()
function:
@app.route("/sell", methods=["GET", "POST"])
@login_required
def sell():
"""Sell shares of stock"""
# Get the stock symbols that user have in order to use it in "sell.html"
options = db.execute("SELECT stock_name FROM purchases WHERE buyer_id = :id")
# Create a dict with key->value pairs
for option in options:
name = ""
option["name"] = option["stock_name"]
# User reached route via POST (as by submitting a form via POST)
if request.method == "POST":
# TODO
flash("Successfully sold!")
return redirect("/")
# Else, user reached route via GET (as by clicking a link or via redirect)
else:
return render_template("sell.html", options = options)
And here is my sell.html:
> {% extends "layout.html" %}
{% block title %}
Sell
{% endblock %}
{% block main %}
<form action="/sell" method="post">
<div class="form-group">
<div class="input-group">
<span class="input-group-adon">Select the stock symbol to sell</span>
<select name="symbol" class="selectpicker form-control">
{% for option in options %}
<option value={{option["name"]}}>{{ option["name"] }}</option>
{% endfor %}
</select>
</div>
<button class="btn btn-danger">Sell Stock</button>
</div>
</form>
{% endblock %}