views:

41

answers:

1

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)
        raise 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

+3  A: 

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())
Drew Sears