【问题标题】:Json in html templatehtml模板中的json
【发布时间】:2017-01-08 04:11:53
【问题描述】:

我使用bottle在html模板中打印一些json,所以我在模板中这样做:

% for rows in url:
    <ul>
        % for cols in rows[0:2]:
            <li>
            {{cols}}
            </li>
        % end
        % for req in rows[2:3]:
        <li>
            {{req}}
        </li>
        % end
    </ul>
% end

结果:

  • http://www.adress/
  • 1.5
  • {'x-xss-保护': '1;模式=块','x-content-type-options': 'nosniff', 'age': '2295260', 'expires': 'Fri, 08 Dec 2017 08:32:02 GMT', 'vary': 'Accept-Encoding', 'server': 'sffe', 'last-modified': '星期四,2016 年 12 月 8 日 01:00:57 GMT','连接':'关闭'}

但我想在列表的最后一项中创建另一个列表, 所以如果我这样做了

% for list in req:
   {{list}}
% end

我明白了

  • x
  • -
  • x
  • s
  • s
  • ...

有没有人想打印这份清单?

【问题讨论】:

    标签: python json bottle


    【解决方案1】:

    你可以插入一个内部循环

    ...
    % for req in rows[2:3]:
        % for line in req:
            <li>
                {{line}}
            </li>
        % end
     % end 
    

    如果它始终是最后一项,您也可以循环遍历它

    ...
    % for line in rows[-1]:
            <li>
                {{line}}
            </li>
    %end
    

    【讨论】:

      猜你喜欢
      • 2010-12-19
      • 1970-01-01
      • 1970-01-01
      • 2013-04-29
      • 1970-01-01
      • 2010-12-18
      • 1970-01-01
      • 2012-12-26
      • 1970-01-01
      相关资源
      最近更新 更多