Say I have a blog on Google AppEngine and wants to print out the id of each post through jinja2.
blog = db.GqlQuery('SELECT * FROM Blog')
self.render('blog.html', blog = blog)
and in the template:
{{% for b in blog %}}
{{b.id}}
{{% endfor %}}
Now I havent added an 'id' field to my DB model, I just want to access the build in datastore ID field. How do I do that?
Have a look at the db key class. When you have an entity you can do:
entity.key().id_or_name()
or in NDB:
entity.key.id()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With