Search code examples
djangoformset

Django formset - custom input HTML


I need to expand a formset's field, so instead of

{{ form.name }}

I'm using something like

<input type="text" name="{{ form.name }}" ... >

My custom implementation does not print the formset prefix, so the HTML I get is

<input type="text" name="name" ... >

But what I would need to have the form working properly with formset is

<input type="text" name="attachments-3-name" ... >

where attachments-x is automatically added.

How can I get that?

I noted there's an helper for ID (auto_id) which prints something similar: id_attachments-3-name; is there something similar for names?


Solution

  • Looks like {{ form.name.html_name }} is what I've been looking for the last 2 hrs.