[Answer]-Django unexpected keyword argument when creating form

1👍

Well, that’s not how forms work. You’re not supposed to process the POST arguments first, and you can’t pass data for individual fields as arguments like that. You’re simply supposed to pass request.POST into the form instantiation as-is.

The way to do a set of multiple identical forms is to use a formset. You can then pass the POST data straight into the formset instantiation, and get validated forms out.

Note that since your form is being used to create model instances, you may want to consider using a modelform (and a model formset, on the same page).

0👍

Django the form.init() accepts an ‘initial’ keyword argument, you could have set the initial values of the form in the following way:

form = AddItemForm(initial = {
                      'name':names[i],
                      'priority':priorities[i],
                      'due_date':due_dates[i],
                   }
               )

Leave a comment