【发布时间】:2017-12-20 17:51:45
【问题描述】:
我正在尝试将查询结果输出到 HTML 表中,并在其旁边放置一个删除实体的链接。
如何从数据存储中检索每个实体的 ID,以便删除链接知道它需要删除哪个实体?我正在使用 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))
【问题讨论】:
-
为什么不向模板发送
userIdentity? -
@GAEfan 我还在这个阶段做实验。不确定我是否需要它。
标签: python google-app-engine google-cloud-datastore jinja2