Django: How to avoid duplicate html id to display a field twice in one form?

I want to generate the same field twice in the same form, which is useful when there is a condition to show the 1st text or the second text: Django will generate:

<!--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"/> 

So there is a duplicate html id, how to avoid it? (I can survive without an identifier generated for these two boxes with a duplicate identifier, but not all the others)

+4
source share
1 answer

If you use

{{ form.element }}

You can do the following:

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


Sorry, I didn’t understand which filter I used: http://djangosnippets.org/snippets/729/

I just changed = to :

+1
source

All Articles