In Django filter statement what's the difference between __exact and equal sign (=)?

前端 未结 2 1849
無奈伤痛
無奈伤痛 2020-12-16 10:38

In Django filter statement what\'s the difference if I write:

.filter(name__exact=\'Alex\')

and

.filter(name=\'Alex\')
         


        
2条回答
  •  天涯浪人
    2020-12-16 11:22

    There is no difference, the second one implies using the __exact.

    From the documentation:

    For example, the following two statements are equivalent:
    >>> Blog.objects.get(id__exact=14)  # Explicit form
    >>> Blog.objects.get(id=14)         
    # __exact is implied This is for convenience, because exact 
    # lookups are the common case.
    

提交回复
热议问题