Reputation: 175
I am trying to output the results of a query into an HTML table and put a link next to it that deletes the entity.
How do I retrieve the ID of each entity from the datastore so that the delete link knows which entity it needs to delete?. I am using Python/Webapp2/Jinja2.
HTML:
<table>
<tr>
<th><b>{{ result.email }}</th>
<th><b>{{ result.date }}</th>
<th><b>{{ result.title }}</th>
<th><b>{{ result.content }}</th>
<th><a href="/delete/{{ ID GOES HERE }}"</th>
</tr>
</table>
Python:
class MyRequestsHandler(webapp2.RequestHandler): # Queries the datastore
def get(self):
user = users.get_current_user()
userIdentity = users.get_current_user().user_id()
#email = users.get_current_user().email()
login_url = users.create_login_url(self.request.path)
logout_url = users.create_logout_url(self.request.path)
q = WorkRequest.query(WorkRequest.userId == userIdentity)
results = q.fetch(10)
template = template_env.get_template('myrequests.html')
context = {
'user': user,
'login_url': login_url,
'logout_url': logout_url,
'results': results,
}
self.response.out.write(template.render(context))
Upvotes: 1
Views: 1060
Reputation: 11360
Are you using a custom ID, or the standard integer ID from ndb? I think what you want is:
{{ result.key.id() }}
depending on what model you are using. But you might consider sending a url safe key
to the template and using that.
Upvotes: 1