为祖先的钥匙创建一个漂亮的网址 [英] Create a good looking url for a key with ancestors

查看:95
本文介绍了为祖先的钥匙创建一个漂亮的网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从ndb的密钥中获取一个实例。该键可能有一个父键,但我不想将任何父键传递给该URL,因为我想要一个漂亮的URL。
我不想将整个密钥字符串传递给url。
这可能吗?

解决方案

这是可能的。但是,在您的代码中,父键将是静态的。



当您获得数字ID时,您只需重新构建密钥。 p $ p $



$ b $ key $ ndb.Key('Somekind','somevalue','kindOfInstance',id)

instance = key.get()#获取实例

'Somekind'是父类的名称。 'somevalue'是父类的字符串标识。 'kindOfInstance'是实例类的名称。你可以使用不带引号的课程。

I need to get an instance from a key from ndb. The key may have a parent key, but I don't want to pass any parent keys to the url, because I want a nice looking url. I don't want to pass the entire key string to the url either. Is this possible?

解决方案

It's possible. But parent key will be static in your code.

When you get numeric id, you just reconstruct key.

id = long(inputId) 
key = ndb.Key('Somekind', 'somevalue', 'kindOfInstance', id)

instance = key.get() # get instance

'Somekind' is name of parent class. 'somevalue' is string id of parent class. 'kindOfInstance' is name of instance class. You may use just class without quotes.

这篇关于为祖先的钥匙创建一个漂亮的网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆