I am trying to program a simple dropdown where I do get data from the MySQLdb connection and cycle woth Flask through the resuls, but the data is not shown correctly. I have consulted and followed other posts yet in my case it does not work (no matter what I do).
Intended result:
<option value="1">Appels</option>
<option value="2">Bananas/option>
<option value="3">Cherries</option>
<option value="4">Peaches</option>
Actual result:
<option value=""> (1, 'Appels') </option>
<option value=""> (2, 'Bananas') </option>
<option value=""> (3, 'Cherries') </option>
<option value=""> (4, 'Peaches') </option>
I got the data in Flask from a MySQL database with MySQLdb with the following code:
@app.route('/testbed', methods = ['POST', 'GET'])
def testbed():
cursor = mysql.connection.cursor()
fruit = cursor.execute("SELECT id, type FROM fruit")
return render_template('testbed.html', fruit=cursor.fetchall())
The corresponding HTML code:
<select name="fldFruitPicker" class="form-select form-select-sm">
{% for type in fruit %}
<option value="{{ id }}"> {{ type }} </option>
{% endfor %}
</select>