Search code examples
google-app-enginepostwebapp2

webapp2 post operation not updating datastore


I am developing a web application using google appengine.

I am trying to update an existing entry in the table but my post operation does not seem to be working.

post script:

r = requests.post("http://localhost:8080", data={'type': 'user', 'id':
'11111', 'name': 'test'})

When running the script there are no errors in the console and when prining r.text I can see the updated name but the page on localhost does not show the updated name and the datastore user still has its previous name.

My model for the main page is:

class Page(webapp2.RequestHandler):
    def get(self):
        ...
    def post(self):
        user = User().get_user(self.request.get('id'))  // query user from data store
        user.name = self.request.get('name')
        user.put()
        // update jinja template

Solution

  • self.request.get('id') is a string. You want to use an integer for the id, or build a key (I am assuming you are using ndb):

    user = ndb.Key('User', int(self.request.get('id'))).get()