Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 2.7 Tornado模板中带有if语句的For循环。可能吗?_Python 2.7_Templates_For Loop_Tornado - Fatal编程技术网

Python 2.7 Tornado模板中带有if语句的For循环。可能吗?

Python 2.7 Tornado模板中带有if语句的For循环。可能吗?,python-2.7,templates,for-loop,tornado,Python 2.7,Templates,For Loop,Tornado,以下是我的模板标记中的一些内容: {% for filename, uuid, i in files %} <div class="content"> {% if i == 0 %} {% for filename, uuid, name in nginx %} <span id="{{ uuid }}" class="{{ name }}">{{ filename }}</span&g

以下是我的模板标记中的一些内容:

{% for filename, uuid, i in files %}
    <div class="content">
        {% if i == 0 %}
            {% for filename, uuid, name in nginx %}
                <span id="{{ uuid }}" class="{{ name }}">{{ filename }}</span>
                <div id="{{ uuid }}" class="{{ name }}">
        {% elif i == 2 %}
            {% for filename, uuid, name in apache %}
                <span id="{{ uuid }}" class="{{ name }}">{{ filename }}</span>
                <div id="{{ uuid }}" class="{{ name }}">
{% end %}
我的列表中有不同数量的文件,nginx和apache,我愿意将它们放在不同的选项卡上

但龙卷风说的是:

File "/usr/lib64/python2.7/site-packages/tornado/template.py", line 837, in _parse
block_body = _parse(reader, template, operator, operator)
File "/usr/lib64/python2.7/site-packages/tornado/template.py", line 789, in _parse
raise ParseError("%s block cannot be attached to %s block" % (operator, in_block))
ParseError: elif block cannot be attached to for block
根据,有forcontinue/break以及if/elif/else支持,但是 tornado模板中是否支持loop+if语句?
如果没有,我如何实现我的目的?

在模板中,缩进不重要,因此必须在每个复合语句后使用
{%end%}
标记:

{% for filename, uuid, i in files %}
<div class="content">
    {% if i == 0 %}
        {% for filename, uuid, name in nginx %}
            <span id="{{ uuid }}" class="{{ name }}">{{ filename }}</span>
            <div id="{{ uuid }}" class="{{ name }}">
        {% end %}
    {% elif i == 2 %}
        {% for filename, uuid, name in apache %}
            <span id="{{ uuid }}" class="{{ name }}">{{ filename }}</span>
            <div id="{{ uuid }}" class="{{ name }}">
        {% end %}
    {% end %}
{% end %}
{%用于文件名、uuid、文件中的i%}
{%i==0%}
{nginx%中的文件名、uuid、名称为%
{{filename}}
{%end%}
{%elif i==2%}
{%表示文件名、uuid、apache%中的名称}
{{filename}}
{%end%}
{%end%}
{%end%}
请注意,在
if/elif
的情况下,您只需要在最后一个
elif
之后有一个
end
;不要在
if
与其
elif
之间放置
end

{% for filename, uuid, i in files %}
<div class="content">
    {% if i == 0 %}
        {% for filename, uuid, name in nginx %}
            <span id="{{ uuid }}" class="{{ name }}">{{ filename }}</span>
            <div id="{{ uuid }}" class="{{ name }}">
        {% end %}
    {% elif i == 2 %}
        {% for filename, uuid, name in apache %}
            <span id="{{ uuid }}" class="{{ name }}">{{ filename }}</span>
            <div id="{{ uuid }}" class="{{ name }}">
        {% end %}
    {% end %}
{% end %}