在NDB和GAE中的put()之后评估条件

2024-04-19 19:48:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要执行一些代码后,我已经把我的实体在数据存储,与NDB。在

假设我有这样的东西。在

ent=Entity()
ent.put()

def after_put():
    assert ...

如果不手动调用函数,我如何实现这一点呢?有什么触发器或回调可以用吗?在


Tags: 数据代码实体putdefassert手动entity
1条回答
网友
1楼 · 发布于 2024-04-19 19:48:27

是的,你可以用钩子。在

NDB offers a lightweight hooking mechanism. By defining a hook, an application can run some code before or after some type of operations; for example, a Model might run some function before every get(). A hook function runs when using the synchronous, asynchronous and multi versions of the appropriate method. For example, a "pre-get" hook would apply to all of get(), get_async(), and get_multi().

https://developers.google.com/appengine/docs/python/ndb/entities#hooks

相关问题 更多 >