• 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

  • 相关阅读:
    014_Python3 循环语句
    013_Python3 条件控制
    012_Python3 斐波纳契数列 + end 关键字
    011_Python3 集合
    010_Python3 字典
    009_Python3 元组
    008_Python3 列表
    006_Python3 数字(Number)
    005_Python3 运算符
    bzoj3160
  • 原文地址:https://www.cnblogs.com/lxmtx/p/13444096.html
Copyright © 2020-2023  润新知