How do I enter an item in the Google AppEngine Data Warehouse?

I want to check if the email is in my database in Appengine, and if not: then enter it in the data store.

I am new to python. Why does this simple code not work? (Also, if there is a better way / more efficient way to write this, tell me)

(I get the error: BadArgumentError: unused positional arguments [1])

class EmailAdd(webapp.RequestHandler):
def get(self):
    query = db.GqlQuery("SELECT * FROM EmailDatabase WHERE emailaddress=':1'", self.request.get('emailaddress'))
    result = query.get()
    if result is None:
        newemail = EmailDatabase()
        newemail.emailaddress = self.request.get('emailaddress')
        newemail.put()

And for reference, this is my db class:

class EmailDatabase(db.Model):
     emailaddress = db.StringProperty()
     date = db.DateTimeProperty(auto_now_add=True)
+3
source share
1 answer

You do not need to use quotation marks when binding the parameter to the request:

query = db.GqlQuery("SELECT * FROM EmailDatabase WHERE emailaddress = :1", self.request.get('emailaddress'))

, :1 emailaddress.

, , (self.request.get('emailaddress')), .

+6

Source: https://habr.com/ru/post/1730370/


All Articles