I want to get select value in HTML and use in python Flask. Because I could not find any way to get select tag option value via Flask, I get the value with JavaScript and then span it in a header. Now, I want to request the header but I could not. I get Key Error. Here is my HTML code.
<label for="filtre_input">Neye göre karşılaştırmak istersiniz?</label>
<select name="filtre_input" id="filt" onchange="filtreinputla();">
<option selected="selected">Kategori</option>
<option value="il">İl</option>
<option value="tur">Tür</option>
<option value="renk">Renk</option>
<option value="duygu">Duygu</option>
</select>
<script type="text/javascript">
function filtreinputla() {
var filtreselect = document.getElementById("filt").value;
console.log(filtreselect);
document.getElementById("filtreselectid").innerHTML = filtreselect;
}
</script>
<h3 id = "filtreselect_p" type = "hidden" name="filtreselect_p"><span id="filtreselectid"></span></h3>
Here is my app.py code.
@app.route("/nd", methods=['POST', 'GET'])
def func():
flash("")
filter = request.headers["filtreselect_p"]
if filter == None:
flash("Please, select something.")
return render_template("index.html")
else:
result = my_function(filter)
flash(result)
return render_template("index.html")
I want to request the header or find a new approach to get select option tag value. Please, help if you can :)