【问题标题】:webapp2 post operation not updating datastorewebapp2 post操作不更新数据存储
【发布时间】:2018-09-18 07:08:07
【问题描述】:

我正在使用 google appengine 开发一个网络应用程序。

我正在尝试更新表中的现有条目,但我的发布操作似乎不起作用。

发布脚本:

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

运行脚本时,控制台中没有错误,打印 r.text 时,我可以看到更新后的名称,但 localhost 上的页面没有显示更新后的名称,并且数据存储区用户仍然具有以前的名称。

我的主页模型是:

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

【问题讨论】:

    标签: google-app-engine post webapp2


    【解决方案1】:

    self.request.get('id')string。您想使用 integer 作为 id,或者构建一个密钥(我假设您使用的是 ndb):

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

    【讨论】:

    • 这仍然没有更新我的数据存储。同样,帖子中的内容已更新,但实际的静态页面和数据存储并未更新。
    • 更新名称字段后打印当前用户不会在用户对象中显示更新后的名称....奇怪
    • Page() 是否连接到您的根 URL http://localhost:8080?可能是数据存储一致性问题。等待 10 秒,然后再次检查更改。
    • 另外,登录 self.request 以查看发布的内容。
    猜你喜欢
    • 2020-11-11
    • 1970-01-01
    • 1970-01-01
    • 2019-06-29
    • 2011-08-06
    • 1970-01-01
    • 2015-12-17
    • 1970-01-01
    • 2015-11-27
    相关资源
    最近更新 更多