'Getting bootstrap dropdown value return to work in flask
I am trying to get a value (player) from the dropdown select. Once I click the dropdown button, I want the value 'player' to get sent to flask and render the new player's image on the website. HTML:
<form method="POST">
<div class="input-group">
<select class="custom-select" id="inputGroupSelect04" name="player" value="{{ player }}">
{% for key, value in team.items() %}
<option value={{ value }}>{{ value }}</option>
{% endfor %}
</select>
<div class="input-group-append">
<button class="btn btn-outline-secondary" type="submit">Select</button>
</div>
</div>
</form>
<img src="/static/{{ player }}.png" alt="{{ player }}">
Flask:
@app.route("/", methods=['POST', 'GET'])
def main_page():
player = okc[1628983]
if request.method == "POST":
print("this posted")
player = request.form.get('player')
print(request.form.get('player'))
return render_template("index.html", team=okc, player=player)
return render_template("index.html", team=okc, player=player)
Solution 1:[1]
instead of your:
player = request.form.get('player')
you can try this:
player = request.form['player']
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Hammam Abo Jamous |
