how to retrieve data from database using raw SQL not django ORM

22 views
Skip to first unread message

leb dev

unread,
Oct 14, 2019, 6:28:24 AM10/14/19
to Django users
0

I have a django project that is connected to SQL server database and when i tried to click button to retrieve data from the database the system crash .

i am trying to convert the below syntax in ORM into raw sql:

dbEntry = Person_.objects.get(pk =pk) 

Note : I am not using ORM

once i tried to perform the task the system crash and display:

getEvents() got unexpected keyword argument "id"

urls.py

path("events/<int:id>/",getEvents,name = "getEvents"),

views.py

def getEvents(request,pid):
  q1 = cuesor.execute("Select Person_.ID FROM Person_ WHERE ID = pid")
  print("q1=",q1)
  qresult = q1.fetchone()
  print("qresult",qresult)
  return render(request,"connect.html",{"qresult":qresult})

list.html

<form method = "GET" action = "{% url 'getEvents' obj.0 %}"# obj is the iterator --- 0 is the first field in the table == ID
   <button class = "btn btn-primary">get details</button>
</form>

display.html

{% for row in qresult %}
  <p> {{ row.0 }} </p>
{% endfor %}

Kasper Laudrup

unread,
Oct 14, 2019, 7:54:07 AM10/14/19
to django...@googlegroups.com
Hi Leb Dev,

On 14/10/2019 08.28, leb dev wrote:
>
> once i tried to perform the task the system crash and display:
>
> getEvents() got unexpected keyword argument "id >

That error message is pretty clear. Look at your getEvents() function.
It doesn't take a keyword argument, while in your urls.py:

>
> |path("events/<int:id>/",getEvents,name ="getEvents"),|
>

You are calling getEvents() with a keyword argument named id, as the
error message states. Change your getEvents() function to accept id as a
keyword argument instead of the pid positional argument.

Kind regards,

Kasper Laudrup

Kanyamahanga Hubert

unread,
Oct 14, 2019, 11:23:52 PM10/14/19
to django...@googlegroups.com
Your error message is pretty clear. Change a little bit your urls.py to take pk keywords like this:
path("events/<int:pk>/",getEvents,name = "getEvents"),


--
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/013776f5-a699-3ab2-d7af-81616f5783de%40stacktrace.dk.
Reply all
Reply to author
Forward
0 new messages