使用jinja2的G+集成上市活动

2024-05-18 08:35:08 发布

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

我试图用传统的HTML(appengine app)来表示G+活动的列表。我给G+服务打了个电话。我拿到了收藏品。然后我用Jinja2发送这个变量。最后,当我尝试在HTML上迭代时,我遇到了问题

主.py

   actividades = servicio.activities().list(userId='me', collection='public', maxResults='2').execute(http=http)

   plantilla_values = {
      'actividades': actividades,
   }

   template = Entorno_Jinja.get_template('index.html')
   self.response.write(template.render(plantilla_values))

index.html(使用jinja2)

    {% for a in actividades%}
      <li>{{a}}</li>
    {% endfor %}

“actividades”变量值:

{u'updated': u'2014-10-20T16:55:25.402Z', u'kind': u'plus#activityFeed', u'nextPageToken': u'Cg0Qq5bbpOO7wQIgACgBEhQIABCQ95Om2bvBAhjo-LTftLHBAhgC', u'title': u'Google+ List of Activities for Collection PUBLIC', u'etag': u'"Vea_b94Y77GDGgRK7gFNPnolKQw/TIMAz5AmENqGsq38jyfD5oSPWAs"', u'items': [{u'updated': u'2014-10-20T16:55:25.402Z', u'kind': u'plus#activity', u'actor': {u'image': {u'url': u'https://....

活动架构:

{
  "kind": "plus#activityFeed",
  "etag": etag,
  "nextPageToken": string,
  "selfLink": string,
  "nextLink": string,
  "title": string,
  "updated": datetime,
  "id": string,
  "items": [
    activities Resource
  ]
}

目标是表示“项目”信息。因此,将for转换为其他for


Tags: httpforstringindexhtmlplustemplateactivities
2条回答

函数代码如下(类似于Monte Bel注释,但使用“[]”表示集合或属性): 在这种情况下,您可以迭代到项目中,并显示每个活动标题。

{% for a in actividades['items'] %}
<li>{{a['title']}}</li>
{% endfor %}

谢谢

“actividades”被截断了,但应该是

{% for a in actividades.items %} <li>{{a.insert_correct_key_or_property_name_here}}</li> {% endfor %}

相关问题 更多 >