...I even tried request.form.get("symbol_list").

{% extends "layout.html" %}

{% block title %}
{% endblock title %}

{% block main %}

<form action="/sell" method="post">

  <select name = "symbols">
  <size = len_symbol_row_values>
    {% for elements in symbol_row_values %}
      {% for element in elements %}

    <option value = "symbol_list"> {{element}}  </option>
      {% endfor %}
    {% endfor %}

      <input name="counter" placeholder="Shares" type="number" step="1" min="1"/>
         <button class="btn btn-primary" type="submit">sell</button>

{% endblock %}

Here is what my database looks like looks like. I left the database empty but in stock_info there can be a duplicate in more then one col for id. Ex 1 Can appear in two columns.

database name: users

id | username | hash | total_cash | cash_after_purchase

database name: stock_info

id | stock_symbol | stock_name | shares | stock_price | stock_total

sell application

current_id = session["user_id_2"]
db_stock_symbol = db.execute("SELECT stock_symbol FROM stock_info WHERE id = :user_id",
user_id  = current_id)

symbol_row_values = [list(i.values()) for i in db_stock_symbol]
len_symbol_row_values = len(symbol_row_values)

return render_template("sell.html",symbol_row_values = symbol_row_values ,len_symbol_row_values = len_symbol_row_values)
  • What is in symbol_row_values? Unrelated, the names per specification must be "symbol" and "shares", not "symbols" and "counter".
    – Blauelf
    Aug 21 '19 at 11:47
  • It is just the number of symbols. It is a really bad name. For example I could have AAPL , GOOG etc. If I have AAPL it comes back as 1. If I have AAPL and GOOG it would come back as two. I added what my databases look like to the main post to get a better understanding. @Blauelf
    – grggthwrth
    Aug 22 '19 at 0:17
  • Shouldn't you pass a list of owned symbols instead?
    – Blauelf
    Aug 22 '19 at 5:28
  • They are owned symbols. @Blauelf
    – grggthwrth
    Aug 22 '19 at 18:42
  • Didn't you just say it is a list of numbers? The checker, following the specification, will call /buy and /sell with symbol and shares, it will not use numbers for the symbol.
    – Blauelf
    Aug 23 '19 at 8:55

<size = len_symbol_row_values> does not make any sense to me. I don't think your browser will like it either.

I guess what you meant is having {{element}} not only for the content, but also for the value of the option element, like <option value="{{element}}">{{element}}</option>. I also added company name, owned shares, and current price to the text (but not to the option value), just like the drop-down menu itself that's personal touch, doesn't have to be like that.

I find your nested loops a bit confusing, as your inner lists all have exactly one element. If you are going to repackage the symbols, you could do like

symbol_list = [row["stock_symbol"] for row in db_stock_symbol]

and not have an inner loop. Or pass db_stock_symbol directly, and access the ["stock_symbol"] elements of its rows in the Jinja template. Might look like

return render_template("sell.html", stocks=db_stock_symbol)


<select name="symbol">
{% for stock in stocks %}
    <option value="{{stock["stock_symbol"]}}">{{stock["stock_symbol"]}}</option>
{% endfor %}

The column name "stock_symbol" is a bit odd, given that a table "stock_info" is mostly about stocks, and symbols exist only in that context. Also, a field "id" in this table is misleading, as it is not a native id of this entry, but a foreign id from the "users" table, so the convention is to name it "user_id".

And your POST path should evaluate request.form.get("symbol") and request.form.get("shares"), not "symbols" or "counter". Those names are part of the specification, and may not be changed.

You must log in to answer this question.

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