Python 如何在Jinja2中选中复选框
我正在学习flask编程,不知道如何检查无线电输入,以下是我正在使用的html模板:Python 如何在Jinja2中选中复选框,python,html,flask,jinja2,Python,Html,Flask,Jinja2,我正在学习flask编程,不知道如何检查无线电输入,以下是我正在使用的html模板: <form method = "POST" action="/proxy_settings"> <input type="radio" name="proxy_mode" value = '0'>Auto <br> <input type="radio&qu
<form method = "POST" action="/proxy_settings">
<input type="radio" name="proxy_mode" value = '0'>Auto
<br>
<input type="radio" name="proxy_mode" value = '1'>Manual
<br>
<br>
<section>
<table border="1">
<tr>
<td>Description</td>
<td>delay</td>
<td>select</td>
</tr>
{% for node_name, node_delay in node_list.items() %}
<tr>
<td>{{node_name}}</td>
<td>{{node_delay}}</td>
<td><input type="radio" name="proxy_node"></td>
</tr>
{% endfor %}
</table>
</section>
<br>
<section>
<button type="submit">CONFIRM</button>
</section>
</form>
我的问题是:
<input type="radio" name="proxy_mode" value = '0' {% if proxy_mode == 0 %} checked=true {% endif %}>Auto
<br>
<input type="radio" name="proxy_mode" value = '1' {% if proxy_mode == 1 %} checked=true {% endif %}>Manual
自动
手册
提前谢谢 在阅读了Jinja2之后,我找到了解决问题的方法: 使用Jinja语句控制整个html标记,而不是此标记的属性。因此,修改后的表单如下所示:
<form method = "POST" action="/proxy_settings">
{% if proxy_mode == '0' %}
<input type="radio" name="proxy_mode" value = '0' checked=true>Auto
{% else %}
<input type="radio" name="proxy_mode" value = '0'>Auto
{% endif %}
<br>
{% if proxy_mode == '1' %}
<input type="radio" name="proxy_mode" value = '1' checked=true>Manual
{% else %}
<input type="radio" name="proxy_mode" value = '1'>Manual
{% endif %}
<br>
<br>
<section>
<table border="1">
<tr>
<td>Description</td>
<td>delay</td>
<td>select</td>
</tr>
{% for node_name, node_delay in node_list.items() %}
<tr>
<td>{{node_name}}</td>
<td>{{node_delay}}</td>
{% if loop.index0 == proxy_node|int %}
<td><input type="radio" name="proxy_node" value={{loop.index0}} checked=true></td>
{% else %}
<td><input type="radio" name="proxy_node" value={{loop.index0}}></td>
{% endif %}
</tr>
{% endfor %}
</table>
</section>
<br>
<section>
<button type="submit">CONFIRM</button>
</section>
</form>
{%if proxy_mode=='0%}
自动的
{%else%}
自动的
{%endif%}
{%if proxy_mode=='1%}
手册
{%else%}
手册
{%endif%}
描述
延迟
选择
{%对于节点\名称,节点\列表中的节点\延迟。items()%}
{{node_name}}
{{node_delay}}
{%if loop.index0==proxy_node | int%}
{%else%}
{%endif%}
{%endfor%}
证实
希望这个答案能帮助那些看过这个问题的人。谢谢
<form method = "POST" action="/proxy_settings">
{% if proxy_mode == '0' %}
<input type="radio" name="proxy_mode" value = '0' checked=true>Auto
{% else %}
<input type="radio" name="proxy_mode" value = '0'>Auto
{% endif %}
<br>
{% if proxy_mode == '1' %}
<input type="radio" name="proxy_mode" value = '1' checked=true>Manual
{% else %}
<input type="radio" name="proxy_mode" value = '1'>Manual
{% endif %}
<br>
<br>
<section>
<table border="1">
<tr>
<td>Description</td>
<td>delay</td>
<td>select</td>
</tr>
{% for node_name, node_delay in node_list.items() %}
<tr>
<td>{{node_name}}</td>
<td>{{node_delay}}</td>
{% if loop.index0 == proxy_node|int %}
<td><input type="radio" name="proxy_node" value={{loop.index0}} checked=true></td>
{% else %}
<td><input type="radio" name="proxy_node" value={{loop.index0}}></td>
{% endif %}
</tr>
{% endfor %}
</table>
</section>
<br>
<section>
<button type="submit">CONFIRM</button>
</section>
</form>