Google App Engine: get the entity key for use in the template

Assuming I have the following:

class Person(db.Model):
  name = db.StringProperty()

I would like to print all the names in the html file using the template.

template_values = {'list': Person.all()}

And the template will look like this:

{% for person in list %}
<form>
  <p>{{ person.name}} </p>
  <button type="button" name="**{{ person.id }}**">Delete!</button>
</form>
{% endfor %}

Ideally, I would like to use person.key or person.id to then delete the entry using the key, but this does not work. Any ideas how I can do this?

+3
source share
2 answers

Found a solution in one of the code examples:

template_values = {'list': **list**(Person.all())}

And in the template:

{% for person in list %}
<form>
  <p>{{ person.name}}</p>
  <button type="button" name="**{{ person.key }}**">Delete!</button>
</form>
{% endfor %}

As recommended by Wooble, you can try Person.all () instead of fetch (SOME_NUMBER).

0
source

Use {{person.key.id}}, not just {{id}}. This will call each object .key().id()method (s).

, Person.all() ; .all() db.Query, , , RPC ; - Person.all().fetch(SOME_NUMBER), SOME_NUMBER ( , .)

+6

Source: https://habr.com/ru/post/1772278/


All Articles