Python 在任何模板系统中,是否有一种简单的方法来保持收音机框的选中状态?
如果我想在提交表单后保持状态,我真的必须为每一个Python 在任何模板系统中,是否有一种简单的方法来保持收音机框的选中状态?,python,html,templates,web,Python,Html,Templates,Web,如果我想在提交表单后保持状态,我真的必须为每一个电台或复选框忍受这种情况吗 <input type="radio" name="all_gene" class="open_gene" checked= % if request.GET.get("all_gene") == "0": checked="checked" % endif value="0"> <label>
电台
或复选框
忍受这种情况吗
<input type="radio" name="all_gene" class="open_gene" checked=
% if request.GET.get("all_gene") == "0":
checked="checked"
% endif
value="0"> <label>One gene</label>
<input type="radio" name="all_gene" class="open_gene" checked=
% if request.GET.get("all_gene") == "1":
checked="checked"
% endif
value="1"> <label>Another gene</label>
一个基因
另一个基因
您可以随时提供对象和索引的名称,并使用“for”循环来创建对象和使用“get”函数。有些浏览器不就是神奇地记住了这些东西吗?无论如何,您可以尝试使用过滤器而不是{%if%}
s,这样至少可以节省一点空间