python – Django:如何避免在同一表单中两次显示字段的重复html
发布时间:2020-12-20 13:24:55 所属栏目:Python 来源:网络整理
导读:我想以相同的形式生成两次相同的字段,这在有条件显示第一个textInput或第二个textInput时很有用: Django将生成: !--same form --input type="radio" value="good_price"/ !-- show good price if this is checked --input type="radio" value="bad_price"/
我想以相同的形式生成两次相同的字段,这在有条件显示第一个textInput或第二个textInput时很有用:
Django将生成: <!--same form --> <input type="radio" value="good_price"/> <!-- show good price if this is checked --> <input type="radio" value="bad_price"/> <!-- show bad price if this is checked --> <!--1st --> Good price <input id="id_name"..../> <input id="options_with_good_price"/> <!--2nd --> Bad Price <input id="id_name".../> <input id="options_with_bad_price"/> 所以有重复的html id,如何避免呢? (我可以生存,没有为这两个带有重复ID的盒子生成id,但不是所有其他盒子) 解决方法
如果你正在使用
{{form.element}} 您可以执行以下操作: {{form.element | attr:“id:another_name”}} 抱歉没有意识到我使用的模板过滤器: 我刚刚改变了=: (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |