2

How can I make array with values of row in database Sqlite in python?

def dropname():
   db = get_db()
   dropname  = db.execute("SELECT name FROM names WHERE ID_dol = 1")
   dropname = cur.fetchall()
   return render_template('form_names.html', dropname=dropname)

2 Answers 2

2

fetchall() returns a list of rows, where each row is a list of column values.

You have to extract the first column value from each row:

dropname = [row[0] for row in dropname]
Sign up to request clarification or add additional context in comments.

Comments

-1

problem is that you're not fetching the query in the variable "dropname"

you should replace

dropname = cur.fetchall()
return render_template('form_names.html', dropname=dropname)

by

data = dropname.fetchall()
return render_template('form_names.html', dropname=data)

then in your HTML to call it, you do

{{ dropname[n] }}

where n is the column's index

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.