split(,)分割字符串
{% for i in mem_used[0]%} {% if loop.last == True %} {{ (i/1073741824)|round(precision=2) }} {% endif %}{% endfor %}
取得mem_used的第一组数据,如果当前是最后一组。就取当前数据,round(precision=2)转换成2位小数点
{% if user in users %}条件1{% elif loop.index == 1%}条件2{% elif loop.index == 2 %}条件3{% elif loop.index == 3 %}条件4{% elif loop.index == 4 %}条件5{%else%}最后条件{% endif %}
条件判断语句{% elif %}可一直无限使用
{% for user in user %}当循环有数据时执行此处{% else %}当无循环时执行些处{% endfor %}
可用于没有数据时告知用户没有数据。
<div id="int{{ loop.index }}"></div>
{{ render_snmp_column_line(i[0] ,'line_int',html_id='int'~loop.index,width='100%',height=280,) }}
调用宏里面的FLASH,生成多个要用到 loop.index 做为动态生成ID,可用~加入到宏的变量里,直接加{{loop.index}}会出错这样加才行,~loop.index
{% for r in i %}
<td>
{%- if loop.index0 == 3-%}
{% if r == "1" %}
正在使用
{% elif r == "2" %}
未使用
{% elif r == "3" %}
测试状态
{% endif %}
{% else %}
{{ r }}
{% endif %}
当循环到第三个索引值时,如果是1就显示“正在使用”,如果是2是显示“未使用”,如果是3就显示“测试状态”
{% if process[0] %}
<div class="body_summary">
<div class="summary_box">
<p class="title">系统进程数</p>
<p class="help"></p>
<p class="value">{{ process[1] }}</p>
</div>
<div class="clr"></div>
</div>
<div class="clr" style="margin:10px auto;">
<div id="process"></div>{{ render_snmp_column_line(process[0],'line_process',html_id='process',width="100%",height=280)}}
</div>
{% else %}
{{ snmp_error(hid) }}
{% endif %}
当传入的参数没有数据时,执行{% else %}后面的值
{% if i[2][2] %}IP[{{ i[2][2] }}]{% else %}{% endif %}
判断i有循环就显示,无则空
{% for r in i %}
{% if not loop.index == 1 }//只循环除第1条外的数据
<div class="snmp_summary_box_left" >
<p class="title">
{% if loop.index == 1 %}当前使用 {% elif loop.index == 2 %}最大使用 {% elif loop.index == 3 %}最小使用 {% elif loop.index == 4 %}平均使用 {% endif %}//第一条显示不同的名
<span class="value">{{ r }} %</span>
</p>
</div>
{% endif %}
{% endfor %}
{% if i[3]|int == 1 %}使用中{% elif i[3]|int == 2 %}未使用{% elif i[3]|int == 3 %}测试状态{% endif %}
循环内部判断不需要加{{}},判断不成功,要用|int转换成整数
{{((h_ret.server_mem[0]|int)/1073741824)|round(precision=2,method='common')|gb_unit}}
单位转换
页面变量
{% set s_list = ['SNMP','nginx','apache','lighttpd','mongodb'] %}
{% set s_start = _('获取连接数、吞吐率(请求数/秒)') %}
{% set s_end = _(',以及更多的详细性能报表和分析报告。') %}
{% for i in s_list %}
<div class="type_name">创建
<a href="#" id="{{ i }}" style="color: #058EC4;cursor: pointer;" title="点击进入详细{{ i.title() }}选填页面">{{ i.title() }}</a>
监控任务
</div>
<div class="type_descr">
{% if i == 'SNMP' %}
{{ _('监控SNMP,获得服务器可用率统计、故障信息、网络流量、系统进程、最后状态等详细分析。') }}
{% elif i == 'nginx' %}
{{ s_start + _('、持久连接利用率') + s_end }}
{% elif i == 'mongodb' %}
{{ s_start + _('、锁和索引及内存硬盘使用统计') + s_end }}
{% else %}
{{ s_start + s_end }}
{% endif %}
</div>
{% endfor %}