在Django过滤语句中__exact和等号(=)之间有什么区别? [英] In Django filter statement what's the difference between __exact and equal sign (=)?

查看:4036
本文介绍了在Django过滤语句中__exact和等号(=)之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  .filter(name__exact ='Alex')

  .filter(name ='Alex')

谢谢

解决方案

没有区别,第二个暗示使用__exact。



文档中

 例如,以下两个语句是等价的:
>>> Blog.objects.get(id__exact = 14)#显式表单
>>> Blog.objects.get(id = 14)
#__exact是隐含的这是为了方便,因为确切的
#查找是常见的情况。


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

.filter(name__exact='Alex')

and

.filter(name='Alex')

Thanks

解决方案

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.

这篇关于在Django过滤语句中__exact和等号(=)之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆