Cameron Sima Cameron Sima - 1 year ago 74
Python Question

Google App Engine returning odd values from datastore

I'm trying to do a simple save string to datastore, redirect on that entity's key, then fetch it in the next handler. When I make the call in PDFHandler to fetch the string ( "w" is returned everytime, no matter what I enter.

class Pdf(db.Model):
name = db.StringProperty(required=True)

class InputHandler(Handler):
def get(self):

def post(self):
name = self.request.get('name')

if name:
a = Pdf(name=name)
self.redirect('/key=%s' % a.key())
error = "Please enter your full name."

class PDFHandler(Handler):
def get(self, id):
a = db.Key.from_path('Pdf', id)


application = webapp2.WSGIApplication([
(r'/', InputHandler),
(r'/key=(.)+', PDFHandler),
], debug=True)

Answer Source

In your PDFHandler when you do

a = db.Key.from_path('Pdf', id)

What you are getting is the Key object not the entity yet.

To get the Pdf entity you can do the below

pdf = db.get(a)

Then you can access fields on pdf like etc.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download