Python appengine query not working when using variable

I am trying to use the fetcher method to retrieve items from my data store. If I use the following

def getItem(item_id):
    q = Item.all()
    q.filter("itemid = ", item_id)

He fails because nothing returns. If I hardcode an element like

def getItem(item_id):
    q = Item.all()
    q.filter("itemid = ", 9000)

he chooses just fine and sings fun. I tried every way to make this work. I used

result = db.GqlQuery("SELECT * FROM Item WHERE item_id = :1 LIMIT 1",
    title).fetch(1)

to the same effect. If I hard code the number, great. I tried to set the select statement as a local string, assembling it this way, typing int as a string and nothing. When I display the SELECT statement on the screen, it looks fine. I can cut as to paste the output into a string, and whammo to work. Any help would be appreciated.

+3
1

, :

def getItem(item_id):
    q = Item.all()
    q.filter("itemid = ", int(item_id))

, , , item_id , . int , .

+2

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


All Articles