Create a good looking url for a key with ancestors

放肆的年华 提交于 2019-12-11 05:46:54

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/12675664/create-a-good-looking-url-for-a-key-with-ancestors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!