how to Reference the variable via db.run_in_transaction on google-app-engine
this is my code:
class A(db.Model):
a=db.StringProperty()
class demo(BaseRequestHandler):
def get(self):
a=''
def fn():
global a
a=A(a='www')
a.put()
db.run_in_transaction(fn)
rais开发者_高级运维e Exception(a.key())
and the error is :
raise Exception(a.key())
AttributeError: 'str' object has no attribute 'key'
so how to get the right 'a' ,
thanks
Try this:
class demo(BaseRequestHandler):
def get(self):
def fn():
a=A(a='www')
a.put()
return a
a = db.run_in_transaction(fn)
raise Exception(a.key())
精彩评论