Google应用引擎将嵌套值传递给temp

2024-09-27 23:17:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试用GAE创建一个web应用程序,数据结构由摘要、项目和任务组成。在

每个摘要有多个项目,每个项目依次有多个任务。在摘要页面上,我需要显示摘要下的所有内容,因此:

  • 项目1:任务a、任务b、任务c。。。。在
  • 项目2:任务a,任务c,任务c。。。。 等等。。。在

我使用下面的代码成功地将所有项目显示在一个列表中,但是当涉及到显示每个项目下的任务时,我就迷路了。作为GAE、python和web应用程序的新手,我甚至不知道要搜索的术语,我的搜索也帮不了多少忙……也许这里有人能帮上忙。在

class DocketPage(BaseRequestHandler):
_OUTPUT_TYPES = {
'default': ['text/html', 'html'],
}

def get(self):
 docket = Docket.get(self.request.get('id'))
 docket_name = docket.name
 if not docket:
   self.error(403)
   return

projects_query = Project.all().ancestor(
            docket)
projects = projects_query.fetch(10)

for project in projects:
    tasks_query = Task.all().ancestor(project)
    tasks = tasks_query.fetch(10) 

# Choose a template based on the output type
output_name = self.request.get('output')
output_name_list = DocketPage._OUTPUT_TYPES.keys()
if output_name not in output_name_list:
  output_name = output_name_list[0]
output_type = DocketPage._OUTPUT_TYPES[output_name]

self.response.headers['Content-Type'] = output_type[0]
self.generate('docket_' + output_name + '.' + output_type[1], {
  'docket': docket,
  'projects': projects,
  'tasks' : tasks,
})

我通过以下方式修改代码,使taks显示在模板中。然而,这显然没有帮助,因为项目和任务的数量无法知道。在

^{pr2}$

Tags: 项目nameselfoutputgettypequerylist

热门问题