Thursday, October 10, 2019

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

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 }}

--
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+unsubscribe@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.

No comments:

Post a Comment