+ 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."
4 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
+ 2
Rice Noodle what you did is not in anyway related to how database works in django.
The error is from the last line, when the render function accepts "x" as it's argument, it expects a context of type dict but everything in your code are bugs too.
You can learn the full django tutorial from youtube, search 🔍 for this user "CoreyMS" or "Corey Schafer"