开发者

how to Reference the variable via db.run_in_transaction on google-app-engine

开发者 https://www.devze.com 2023-01-07 15:07 出处:网络
this is my code: class A(db.Model): a=db.StringProperty() class demo(BaseRequestHandler): def get(self): a=\'\'

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())
0

精彩评论

暂无评论...
验证码 换一张
取 消