12👍
✅
You need to include the form id for each form in the formset (it won’t be shown to the user, as it is rendered as a hidden input). Without that form, the value is missing from the POST data, and you get a KeyError
as you are seeing.
From the formset docs:
Notice how we need to explicitly render
{{ form.id }}
. This ensures that the model formset, in the POST case, will work correctly. (This example assumes a primary key named id. If you’ve explicitly defined your own primary key that isn’t called id, make sure it gets rendered.)
In your case, you are looping through the formset with {% for eli in expense_line_item_form %}
, so you need to include {{ eli.id }}
.
Source:stackexchange.com