Getting TypeError while fetching value from table using Python and Django

2024/11/16 1:19:01

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.

Answer

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.

https://en.xdnf.cn/q/119587.html

Related Q&A

ValueError: The view **** didnt return an HttpResponse object. It returned None instead

Im using Django forms to handle user input for some point on my Django app. but it keeps showing this error whenever the user tries to submit the form. ValueError: The view *my view name goes here* di…

Game Development in Python, ruby or LUA? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, argum…

Problem with this error: (-215:Assertion failed) !ssize.empty() in function cv::resize OpenCV

I got stuck with this error after running resize function line: import cv2 import numpy as np import matplotlib.pyplot as pltnet = cv2.dnn.readNetFromDarknet(yolov3_custom.cfg, yolov3_custom_last.weigh…

When I run it tells me this : NameError: name lock is not defined?

• Assume that you have an array (data=[]) containing 500,000 elements and that each element has been assigned a random value between 1 and 10 (random.randint(1,10)) .for i in range (500000):data[i]…

Unable to find null bytes in Python code in Pycharm?

During copy/pasting code I often get null bytes in Python code. Python itself reports general error against module and doesnt specify location of null byte. IDE of my choice like PyCharm, doesnt have c…

remove single quotes in list, split string avoiding the quotes

Is it possible to split a string and to avoid the quotes(single)? I would like to remove the single quotes from a list(keep the list, strings and floats inside:l=[1,2,3,4.5]desired output:l=[1, 2, 3, …

Image Segmentation to Map Cracks

I have this problem that I have been working on recently and I have kind of reached a dead end as I am not sure why the image saved when re opened it is loaded as black image. I have (original) as my b…

operations on column length

Firstly, sorry if I have used the wrong language to explain what Im operating on, Im pretty new to python and still far from being knowledgeable about it.Im currently trying to do operations on the len…

Python: Parse one string into multiple variables?

I am pretty sure that there is a function for this, but I been searching for a while, so decided to simply ask SO instead.I am writing a Python script that parses and analyzes text messages from an inp…

How do I pull multiple values from html page using python?

Im performing some data analysis for my own knowledge from nhl spread/betting odds information. Im able to pull some information, but Not the entire data set. I want to pull the list of games and the a…