Your code would work if you were calling .get()
or .fetch(1)
on the GqlQuery object.
Example:
user = db.GqlQuery("select * from User where user_id = :1", username).get()
if user:
# now `user` will contain a value if the query returns a value or None if not
You should prefer use of query parameters to string-interpolation as using the API makes your code less vulnerable to SQL-injection attack.