query.filter和gql

时间:2012-05-13 17:28:23

标签: python google-app-engine google-cloud-datastore gql

我正在尝试这个功能,但是出了点问题。我存储了名称“John”,但当我将约翰传递给username_并调用check_user时,输出始终为return results,即使该名称未存储在Google数据存储中。为什么呢?

def check_user(self, username_):
    query = db.Query(Registrations)
    results = query.filter('username =', username_)
    if results:
        return results

user_username = self.request.get('username')
check_username_valid = self.check_user(user_username)

 if not check_username_valid:
    error_username_exists="Username already exists"

对于GQL,我如何将变量username_传递给查询?像:

 qr = db.GqlQuery("Select * from Registrations Where username = ?????")

1 个答案:

答案 0 :(得分:4)

结果是查询对象不是结果,您需要调用query.filter('username =', username_).get()返回单个结果,或query.filter('username =', username_).fetch()返回所有结果。