I understand that, by default, Django auto-populates id for each form field upon rendering with the format id_for_%s. One can modify the format by providing the auto_id argument with a different format as its value to the Form constructor.
That’s not exactly what I am looking for, however. What I want to accomplish is changing the id of just one of the many fields in my form. Also, the solution should not break the use of form = MyForm(request.POST).
PS. MyForm is a model form, so each id is derived from its corresponding Model field.
Thanks for helping out.
The forms framework appears to generate labels here:
Which means you can just supply your field widget with an “id” key to set it to whatever you’d like.
Or override init and set the attrs after form initialization.
I don’t see how this could break a form as django’s forms framework isn’t ever aware of HTML ids (that data is not passed to the server…)