+ 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."
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.
+ 2
Your data will be needed as a dictionary.
+ 2
Arnesh Thanks it works i am verry happy :D