Am querying from a table already in production and need data to be real time hence the reason of using the raw sql. Let me modify and see whether it works
On Monday, June 22, 2020 at 10:03:22 PM UTC+3, larry....@gmail.com wrote: > > On Sat, Jun 20, 2020 at 11:41 AM Faith Mwai <fam...@gmail.com > <javascript:>> wrote: > > > > Am having a challenge of displaying data into my template table, the > function is; > > > > def customers(request): > > if request.method == 'POST': > > accountno = request.POST['accountno'] > > id= request.POST['id'] > > Mobilenumber = request.POST['Mobilenumber'] > > cursor = con.cursor() > > querystring = ("Select Messages, amount, date from Accounts where > accountno = 'accountno' or Mobilenumber = 'Mobilenumber' ") > > > > cursor.execute(querystring) > > > > rows = cursor.fetchall() > > context = {'querystring': querystring} > > con.close() > > if cursor.rowcount == 0: > > return render(request,'kplcapp/customers.html', context) > > else: > > rows = cursor.fetchall() > > return render('kplcapp/customers.html', context) > > return render(request, 'kplcapp/customers.html', context) > > > > if 'print' in request.form: > > df = pd.DataFrame(result) > > df.to_excel(r"C:\Users\Public\Documents\data3.xlsx") > > else: > > return render(request, 'kplcapp/customers.html', context) > > Why are you using raw SQL for such a simple query. In any case you > need to replace the strings with the variables. > > querystring = ("Select Messages, amount, date from Accounts where > accountno = '%s' or Mobilenumber = '%s' " % (accountno, Mobilenumber)) > -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/0f626f4f-0067-4fd1-a015-2c5493a9ecc9o%40googlegroups.com.