Diango中的查询条件

属性__运算符=值

1、__gt  大于

2、__lt  小于

3、__gte  大于等于

4、__lte  小于等于

5、in

  表示在某一集合中。

6、contains

  是否包含,对大小写敏感,相当于like。

# 查询名字中包含a的人
a_persons = persons.filter(p_name__icontains=('a'))
<h3>查询姓名中包含a的所有人</h3>
    {% for a_person in persons %}
        <li>{{a_person.p_name}}</li>
    {% endfor %}

 

7、startswith

  表示以...开头,大小写敏感。

# 查询姓名以b开头的人
s_persons = persons.filter(p_name__istartswith=('b'))

 

8、endswith

  表示以...结尾,大小写敏感。

# 查询姓名以s结尾的人
e_persons = persons.filter(p_name__iendswith=('s'))

 

9、exact

  表示判断,大小写敏感,等价于=。

10、i(ignore)

  表示忽略大小写。

  icontains

  istartswith

  iendswith

  iexact

posted @ 2020-08-06 08:34  梅梅不想踩坑  阅读(93)  评论(0编辑  收藏  举报