In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article shows you the difference between Get and Filter in Django. The content is concise and easy to understand. It will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
Define a Model
Class User (models.Model):
Name = models.CharField ('name', max_length=20,default='')
Age = models.CharField ('age', max_length=20,default='')
Simulation data:
User data:
Id name age
1 zhangsan 17
2 lisi 17
First, let's talk about the get usage of Django:
If we want to get a User whose name is zhangsan:
User = User.objects.get (name= "zhangsan")
At this point, you will get a user object whose name is zhangsan
If I want to get a User with an age of 17:
User = User.objects.get (age= "17")
An error is reported at this point, because the Get method: an object result that can only get a unique value. If it matches several objects, it will report an error; if none of them match, it will also report an error.
Second, let's talk about the filter usage of Django:
If we want to get a User whose name is zhangsan:
User = User.objects.filter (name= "zhangsan")
You will get a Queryset object. The first object is the User object of zhangsan, which is the same as the zhangsan obtained by get.
If we want to get a User with an age of 17:
User = User.objects.filter (age= "17")
The test still gets a Queryset object with two objects in it, one is the User object of zhangsan and the other is the User object of lisi
If we get an object that does not exist, we will return an empty [], but this is not a list and cannot be done with the operation method of list
What is the difference between Get and Filter in Django? have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.