On Sat, Jun 20, 2020 at 11:41 AM Faith Mwai <[email protected]> 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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACwCsY76PTax6MrD3zL99NJEB%3DSnnoP5izVJczQxFqBbKhbWaw%40mail.gmail.com.

Reply via email to