I am getting error while fetching value from table using Python and Django. The error is below:
Exception Type: TypeError
Exception Value:
not all arguments converted during string formatting
My code is below:
rname = request.POST.get('rname')
keyword = '%' + rname + '%'all_value = Meeting.objects.raw("SELECT * FROM booking_meeting WHERE room_name LIKE ? ", (keyword,))
Here I am getting the error.
You must use %s
as the placeholder instead of ?
:
all_value = Meeting.objects.raw("SELECT * FROM booking_meeting WHERE room_name LIKE %s ", (keyword,))
See the documentation at https://docs.djangoproject.com/en/1.11/topics/db/sql/#connections-and-cursors:
Also note that Django expects the "%s" placeholder, not the "?" placeholder, which is used by the SQLite Python bindings. This is for the sake of consistency and sanity.