我正在尝试使用iexact我的Django应用程序.
我在我的数据库类的物品test,TEST,tEsT,和TesT.
我试图找出test我的数据库是否有任何形式.好像我需要使用iexact但是我尝试使用它我收到了一个错误.
这是我的代码片段.
def item_search(x):
item = x.column_in_database
if test__iexact = 'test' in item:
return 1; #this is just pseduocode for stackoverflow
elif
return 0; #this is just pseduocode for stackoverflow
Run Code Online (Sandbox Code Playgroud)
我尝试过各种各样的方法,但我仍然无法让它发挥作用.
这很困惑.
__iexact是你在Django查询过滤器中使用的东西.Django在将查询发送到数据库时将其转换为相关的SQL.它不是Python关键字,您不能只test__iexact在声明中说并希望它能够正常工作.
在普通代码中进行不区分大小写匹配的常用方法就是将双方转换为相同的大小写,即更低:
if 'test' in item.lower():
Run Code Online (Sandbox Code Playgroud)