2011-04-08 124 views
7

從我讀過的東西,這是我應該怎麼檢查任何記錄......檢查在App Engine數據存儲中存在記錄

v = PC_Applications.all().filter('column =', value) 
if not v: 
    return False 

但這返回一個錯誤!

IndexError: The query returned fewer than 1 results

任何想法做到這一點?我讀過.count()是一個不錯的選擇。我是Python和App Engine的新手,非常感謝您的耐心等待!

回答

7
if not v.get(): 

App Engine, Query Class get()

Executes the query, then returns the first result, or None if the query returned no results.

+0

謝謝!我沒有仔細閱讀文檔。 – Ryan 2011-04-09 11:25:04

3

這應該工作:

q = db.Query(PC_Applications, keys_only = True) 
if not q.get(): 
    return false 

我覺得.all().filter('column =', value).count更糟糕,因爲它不是做純鍵查詢。

0

如果你真的想使用的記錄,這樣做:

results = PC_Applications.all().filter('column =', value).fetch(how_many_you_want) 
if results: 
    do_something_to_display_them() 
else: 
    do_something_else() 
相關問題