Query.filter and gql

I am trying to use this function, however something is wrong. I saved the name "John", but when I pass john on username_and is called check_user, the output is always return results, even if the name is not stored in the Google data store. Why?

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"

In the case of GQL, how can I pass a variable username_to the query? as:

 qr = db.GqlQuery("Select * from Registrations Where username = ?????")
+3
source share
1 answer

the result is a query object, not a result, you need to call query.filter('username =', username_).get()to return a single result or query.filter('username =', username_).fetch()to return all of them.

+4
source

All Articles