在valu列中查找子字符串

2024-09-30 22:16:45 发布

您现在位置:Python中文网/ 问答频道 /正文

在Postgresql数据库中有page表,用于保存页面信息。 在页面创建过程中,空格 is added in the pagetitle值,但在代码中,我从pagetitle-Detailed findings查找页面对象。所以有办法找到这个(就像python中的子字符串>>> "abc".__contains__("a")

代码为:

>>> page.objects.filter(pagetitle = "Detailed findings", doc=a)
[]
>>> page.objects.filter(pagetitle = "Detailed findings ", doc=a)
[<page: o-0235931>]

谢谢你

正在工作

>>> page.objects.filter(pagetitle__contains="Detailed findings", doc=a)
[<page: o-0235931>]
>>> page.objects.filter(pagetitle__contains="detailed findings", doc=a)
[]
>>> page.objects.filter(pagetitle__icontains="detailed findings", doc=a)
[<page: o-0235931>]

Tags: 代码信息数据库docobjects过程postgresqlpage