Reputation: 9
I need to fill my drop-down menu with some information that I have in my Database. Everything is working well, except the query result format.
This is the code in my python file:
results = None
with db:
cur = db.cursor()
sql = "SELECT banco FROM bancos"
try:
cur.execute(sql)
results = cur.fetchall()
return render_template("cadastro.html", results=results)
This is my HTML:
<select name="teste">
{% for r in results %}
<option name="{{ r }}">{{ r }}</option>
{% endfor %}
</select>
It's is filling my drop-down menu with all information that i Want but in this format:
('Banco do ABC Brasil S.A.',)
I dont want the brackets, comma, etc. I just want the result!
How can I do that?
Upvotes: 0
Views: 1837
Reputation: 20739
You are printing out the entire row, which in this case only contains one field, banco
. To print just a specific field, you need to use that field in your template.
Try
<select name="teste">
{% for r in results %}
<option name="{{ r[0] }}">{{ r[0] }}</option>
{% endfor %}
</select>
You may also be able to use r['banco']
or r.banco
depending on your database driver.
Upvotes: 2