基于同一列表迭代多个for循环

时间:2018-10-03 16:34:05

标签: python django python-3.x django-templates

在我的django模板中,我需要基于相同的压缩列表添加两个循环。不幸的是,似乎只执行了第一个循环。

views.py中包含以下代码:

remove

我的模板:

{"name":"xx","description":"aaabbb"}

在渲染时,第二个for循环不会迭代。 呈现的html:

// This is in my component.  Just illustrating here what it is set to.
jsonHeaderOptions = { headers: new HttpHeaders({ 'Content-Type': 'application/json' }) };


  public addCall(dataObject: any) {
    let body = JSON.stringify(dataObject);

    return this.httpClient
      .post(this.uri, body, this.jsonHeaderOptions);
  };

Screenshot

为什么会这样?

1 个答案:

答案 0 :(得分:1)

在Python 3中,zip返回一个生成器:一旦迭代,它就被耗尽。您应该先将其转换为列表:

weekzip = list(zip(weekdays, weekdaynum))