使用Python和Django从表中获取值时获取TypeError [英] Getting TypeError while fetching value from table using Python and Django
本文介绍了使用Python和Django从表中获取值时获取TypeError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用Python和Django从表中获取值时出现错误.错误如下:
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
我的代码如下:
rname = request.POST.get('rname')
keyword = '%' + rname + '%'
all_value = Meeting.objects.raw("SELECT * FROM booking_meeting WHERE room_name LIKE ? ", (keyword,))
在这里我得到了错误.
推荐答案
您必须使用%s
作为占位符,而不是?
:
You must use %s
as the placeholder instead of ?
:
all_value = Meeting.objects.raw("SELECT * FROM booking_meeting WHERE room_name LIKE %s ", (keyword,))
请参阅
还请注意,Django需要使用%s"占位符,而不是?"占位符,由SQLite Python绑定使用.这是为了保持一致和理智.
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.
这篇关于使用Python和Django从表中获取值时获取TypeError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文