[閒聊] python大師請進
現在在寫網頁+資料庫
table取名叫做"products"
在寫if判斷式時遇到一個問題
# 關鍵字
keyword = 'kerycheng'
# 今天日期
today = str(datetime.today().date())
if products.objects.filter(keyword__icontains=keyword) and products.objects.fil
ter(time__contains=today):
我要比對table中的兩個欄位,分別是"keyword"和"time"
資料必須符合這兩個欄位的條件時才會輸出出來
但是輸出出來的東西卻是整個table裡面的資料,完全沒有經過篩選
可是當我把if判斷式改成
if products.objects.filter(keryword__icontains=keyword, time__contains=today):
這時候出來的資料就有被篩選,符合上述兩個條件了
https://imgur.com/mibenxD.jpg
是因為必須要有 > = < 這種結果的時候,才能用and做多條件判斷?
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.40.131.63 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1673689198.A.F68.html
→
01/14 17:45,
1年前
, 1F
01/14 17:45, 1F
→
01/14 17:46,
1年前
, 2F
01/14 17:46, 2F
→
01/14 17:46,
1年前
, 3F
01/14 17:46, 3F
→
01/14 17:47,
1年前
, 4F
01/14 17:47, 4F
推
01/14 17:49,
1年前
, 5F
01/14 17:49, 5F
討論串 (同標題文章)
完整討論串 (本文為第 68 之 69 篇):
閒聊
3
8