Help me | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Help me

def show_data(request): db = sqlite3.connect(":memory:") db = sqlite3.connect("/home/user/Desktop/data.db") cursor = db.cursor() cursor.execute("select * from user") db.commit() x = cursor.fetchall() return render(request , 'first/template.html' , x) How to fix "context must be a dict rather than list."

20th Sep 2020, 11:52 AM
Rice Noodle
Rice Noodle - avatar
3 Answers
+ 4
The item x is a list, but you need to pass a dictionary in the render function. And you can reference a key value pair using the key in the template. You could do: return render(request, 'first/template.html', {data: x}) In the template you could iterate through the list.
20th Sep 2020, 12:21 PM
Arnesh
Arnesh - avatar
+ 2
Your data will be needed as a dictionary.
20th Sep 2020, 12:12 PM
JaScript
JaScript - avatar
+ 2
Arnesh Thanks it works i am verry happy :D
20th Sep 2020, 12:26 PM
Rice Noodle
Rice Noodle - avatar