I'm doing the "sell" part of the Finance pset.

I am trying to display the stocks someone is able to sell on a HTML page with a select menu.

The problem is that they don't display properly on the HTML page (see picture:)

enter image description here

Here is the part of my code that give me this result:

user_id = session["user_id"]
        symbol = db.execute("SELECT symbol FROM transactions WHERE user_id = ?", user_id)

        return render_template("sell.html", symbol = symbol)

I also tried to add [0]["symbol"] at the end of my SQLite request but the list was like this (see picture2):

enter image description here

Here is my jinja template as well:

        <select ><div class="form-group">
            <option disabled selected value="">Symbol</option>
                {% for symbol in symbol %}
            <option value="{{ symbol }}">{{ symbol }}</option>
                {% endfor %}

If someone has an idea, please share it, it would help a lot. Thank you.


symbol is a list of dictionaries; that is what execute returns. Therefore the first result returns each dictionary in the template for symbol in symbol loop. Similarly, symbol[0]["symbol'} returns the string "AAPL", so the second result returns each character from the string in the for loop.

There are any number of ways to transform the list of dictionaries into a list of the values from the dictionaries. Or simply address the values in the template with something like:

<option value="{{ symbol.symbol }}">{{ symbol.symbol }}</option>

You must log in to answer this question.

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