My problem is that I'm not getting any value back from my select form. I pass a list of stocks to the jinja template via return render_template("sell.html", stocks=stocks) and on the sell.html page I have the select form set up as

{% block main %}

<form action="/sell" method="post">
    <div class="form-group">
        <select class="form-control" name="symbol" form="sell">

            {% for stock in stocks %}
            <option value="{{ stock.symbol }}">{{ stock.symbol }}</option>
            {% endfor %}

    <div class="form-group">
        <input class="form-control" name="shares" placeholder="Amount" type="number"/>
    <button class="btn btn-primary" type="submit">Sell</button>

{% endblock %}

This works so far as it shows the stocks correctly on the drop-down menu, but when I try to get the selected value back via symbol = request.form.get("symbol") the returned value is None. (tested by passing the symbol back into the template and just printing it out, it showed None for all selected options).

  • Looks similar to what I have (I only added some additional magic like special case for no stocks or pre-selecting a certain stock, but otherwise almost identical), can you include the code that processes the POST request? Maybe you could do debugging by printing those values to the console? – Blauelf Mar 6 '18 at 10:54
  • Oh, what happens if you add an id="sell" to your form element? I have never seen this form="sell" before (haven't done that much HTML5), it might be the reason. – Blauelf Mar 6 '18 at 10:56
  • That helped me solve it. Problem was that extra form="sell"parameter when I was already working in another form tag. Removing it fixed the problem. – MVierma Mar 6 '18 at 11:20
  • @MVierma please add that as an answer and then accept it so that this question will show as closed. Thanks! – curiouskiwi Mar 7 '18 at 3:52

Solution was to remove the unnecessary form=sell from the select tag as I was already working in one form without noticing.

You must log in to answer this question.

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