【发布时间】:2020-03-12 00:26:56
【问题描述】:
Google Cloud Datastore 使用密钥来识别和查询Entities。这在查询实体时与 Flask.route 的 url 参数配合得很好:
from google.cloud import datastore
client = datastore.Client()
@app.route('/post/<post_id>', methods=['GET', 'POST'])
def post(post_id):
post = client.get(client.key('Post', post_id))
return client
但是,这仅在Post 键没有任何ancestors 时才有效:
Key('Post', 'post123')
但是如果Post 键实际上有ancestors,如下所示呢?
Key('User', 'user123', 'Post', 'post123')
这意味着烧瓶路由将不再处理/post/<post_id>,因为post_id 沿不代表整个实体。
这种情况有哪些可能的解决方案?
【问题讨论】:
标签: flask google-cloud-firestore google-cloud-datastore