2011-10-25 25 views
4

我想以相同的形式,当有情况显示1为textInput或第二为textInput这是有用的两次产生相同的字段: Django会产生:的Django:如何避免重复的HTML ID为显示在相同的形式两次领域?

<!--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生存,但不是所有的人)

+0

你是如何产生这种形式的改变=? –

回答

1

如果您正在使用

{{ form.element }}

你可以做到以下几点:

{{ form.element|attr:"id:another_name" }}


对不起没有实现模板过滤器我用: http://djangosnippets.org/snippets/729/

我只是:

+0

我尝试过了,它不工作,说:“无效的过滤器:‘ATTR’” – eroy4u

+0

使用该模板过滤器:http://djangosnippets.org/snippets/729/ –

+0

还与[Django的部件,调整]作品( https://github.com/kmike/django-widget-tweaks),相同的语法。 – frnhr

相关问题