django print all record in the cmd but display the last one on template

10 views
Skip to first unread message

leb dev

unread,
Oct 11, 2019, 2:33:56 AM10/11/19
to Django users
i have a function that retrieve data from sql server database where i am using **fetchall()** then  for loop 
the retrieved data are all printed on the **cmd console** but when i tried to display these result on the template it **only display the last record**.

views.py
========
def search(request):

      query = cursor.execute('Select id, fullname from person')
      result = query.fetchall()
      for row in result:
        print("ID==>",id)
        IPD=row[0]
      return render(request,"test.html",{"IPD":IPD})

test.html
========

      {{ IPD }}

Raja Sekar Sampath

unread,
Oct 11, 2019, 3:43:47 AM10/11/19
to django...@googlegroups.com
Hi,

Convert the variable IPD into an array or render result variable on template

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/68025e0a-81cf-4e62-bd15-14e2006e0157%40googlegroups.com.


--
Thanks & Regards,

Raja Sekar Sampath
Reply all
Reply to author
Forward
0 new messages