Following is the simple database model i have:
class Notes(db.Model):
text = db.StringProperty(multiline=True)
date = db.DateTimeProperty(auto_now_add=True)
Now in the url handler, i send all the notes to the template as follows:
class MainPage(webapp2.RequestHandler):
def get(self):
notes = Notes.all()
self.render_template("index.html", {'notes':notes})
In the template i am using jinja2 templating engine, i want the id
of each of the notes to be printed, so that i can embed an edit link, somewhat like this:
{% for note in notes %}
<p>
{{ note.text }} <br>
{{ note.date }} <br>
(<a href ="edit/{{note.key.id}}">edit </a>)
{% endfor %}
But the trouble is, i dont see anything printed, in place of note.key.id
As per the docs over here key
class represents a unique key for a database entity and this has a method id
, its a numeric value. for a single note from the collection of notes i want the id
of the note.
If i use the django templating engine i get the values {{ notes.key.id }}
printed, but with jinja2
i dont see it.
How can i do this?
Well replace the href
line with the following:
(<a href ="edit/{{note.key().id()}}">edit </a>)
This shall be enough.
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