Skip to content Skip to sidebar Skip to footer

Linking To Entity From List

I have a Consults page that lists consults in the datastore. The list loop is like this: {% for consult in consults %} {{ consult

Solution 1:

From Retrieving Entities from Keys:

You can also use an entity's key to obtain an encoded string suitable for embedding in a URL:

url_string = sandy_key.urlsafe()

This produces a result like agVoZWxsb3IPCxIHQWNjb3VudBiZiwIM which can later be used to reconstruct the key and retrieve the original entity:

sandy_key = ndb.Key(urlsafe=url_string)
sandy = sandy_key.get()

So for each consult entity you can obtain a unique URL where you'd display the info about that entity. For example by using a URL parameter:

url = '/display_consult?key=%s' % consult.key.urlsafe()

And in the /display_consult page handler you'd obtain the entity like this:

consult = ndb.Key(urlsafe=request.get('key')).get()

Post a Comment for "Linking To Entity From List"