Django中QuerySet的結果是否為空的判斷


 

沒有用Django自帶的方式對登錄進行認證,就需要自己判斷,

如下:

 1 user = Account.objects.filter(username__exact=username,password__exact=password)
 2  
 3 #Account為自定義model
 4 
 5 #method-1
 6 #user .exists()
 7 # True or False
 8 if user.exists():
 9 //do something
10 
11 #method-2
12 #user .count()==0
13 if result.count() != 0:
14 //do something
15 
16 #method-3
17 if user:
18 //do something

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM