1

Both {{ form.myfield.auto_id }} and {{ form.myfield.id_for_label }} have the same value. Usually it's "id_myfield".

It is usually used to construct forms, so technically they should always be the same.

<label for="{{ form.myfield.id_for_label }}">...</label>
<input id="{{ form.myfield.auto_id }}" />

But I wonder why id_for_label even exists, because it just adds unnecessary overhead to something that can be done with only auto_id. Are there cases where the values are different?

Daniel
  • 3,092
  • 3
  • 32
  • 49

1 Answers1

-1

Django documentation states following

BoundField.id_for_label

By default, this will be the field’s name prefixed by id_ (“id_my_field” for the example above). You may modify the ID by setting attrs on the field’s widget. For example, declaring a field like this:

my_field = forms.CharField(widget=forms.TextInput(attrs={'id': 'myFIELD'}))

iklinac
  • 14,944
  • 4
  • 28
  • 30