How to get form field's id in Django?

user182945 picture user182945 · Sep 21, 2010 · Viewed 53.1k times · Source

Is there any way to get the id of a field in a template?

In the HTML I get: <input name="field_name" id="id_field_name"...

I know I can get the name with {{ field.html_name }}, but is there anything similar for getting the id?
Or can I only get it like this: id_{{ field.html_name }}?

Answer

Will Hardy picture Will Hardy · Sep 22, 2010

You can get the ID like this:

{{ field.auto_id }}